Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
srene committed Nov 5, 2024
1 parent 2a1df20 commit 7e07813
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
8 changes: 4 additions & 4 deletions block/initchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ func (m *Manager) RunInitChain(ctx context.Context) error {
if err != nil {
return err
}
err = m.SetLastSettlementBlockTime(time.Now())
if err != nil {
return err
}
// update the state with only the consensus pubkey
m.Executor.UpdateStateAfterInitChain(m.State, res)
m.Executor.UpdateMempoolAfterInitChain(m.State)
if _, err := m.Store.SaveState(m.State, nil); err != nil {
return err
}

err = m.SetLastSettlementBlockTime(time.Now())
if err != nil {
return err
}
return nil
}
3 changes: 3 additions & 0 deletions block/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"time"

errorsmod "cosmossdk.io/errors"

Expand Down Expand Up @@ -110,6 +111,8 @@ func (e *Executor) UpdateStateAfterInitChain(s *types.State, res *abci.ResponseI
}
// We update the last results hash with the empty hash, to conform with RFC-6962.
copy(s.LastResultsHash[:], merkle.HashFromByteSlices(nil))
s.SetLastBlockTime(time.Now())

}

func (e *Executor) UpdateMempoolAfterInitChain(s *types.State) {
Expand Down
5 changes: 5 additions & 0 deletions block/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ func SubmitLoopInner(
if err != nil {
return err
}
fmt.Println("skew time", skewTime)

types.RollappPendingSubmissionsSkewTimeHours.Set(float64(skewTime.Hours()))

submitter.Nudge()
Expand Down Expand Up @@ -110,6 +112,7 @@ func SubmitLoopInner(
if err != nil {
return err
}
fmt.Println("skew time", skewTime)
types.RollappPendingSubmissionsSkewBytes.Set(float64(pending))
types.RollappPendingSubmissionsSkewBlocks.Set(float64(unsubmittedBlocksNum()))
types.RollappPendingSubmissionsSkewTimeHours.Set(float64(skewTime.Hours()))
Expand Down Expand Up @@ -339,5 +342,7 @@ func (m *Manager) GetSkewTime() (time.Duration, error) {
if err != nil {
return time.Duration(0), err
}
fmt.Println(lastSettlementBlockTime, m.State.GetLastBlockTime())

return m.State.GetLastBlockTime().Sub(lastSettlementBlockTime), nil
}
7 changes: 5 additions & 2 deletions block/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ func (m *Manager) SettlementSyncLoop(ctx context.Context) error {
}
m.logger.Info("Retrieved state update from SL.", "state_index", settlementBatch.StateIndex)

lastBlockTimestamp := settlementBatch.BlockDescriptors[len(settlementBatch.BlockDescriptors)-1].GetTimestamp()
m.SetLastSettlementBlockTime(lastBlockTimestamp)
lastSLBlockTimestamp := settlementBatch.BlockDescriptors[len(settlementBatch.BlockDescriptors)-1].GetTimestamp()
err = m.SetLastSettlementBlockTime(lastSLBlockTimestamp)
if err != nil {
return fmt.Errorf("save last SL block time: %w", err)
}

err = m.ApplyBatchFromSL(settlementBatch.Batch)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions store/storeIface.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Store interface {

// LoadBlock returns block at given height, or error if it's not found in Store.
LoadBlock(height uint64) (*types.Block, error)

// LoadBlockByHash returns block with given block header hash, or error if it's not found in Store.
LoadBlockByHash(hash [32]byte) (*types.Block, error)

Expand All @@ -58,6 +59,7 @@ type Store interface {

// LoadCommit returns commit for a block at given height, or error if it's not found in Store.
LoadCommit(height uint64) (*types.Commit, error)

// LoadCommitByHash returns commit for a block with given block header hash, or error if it's not found in Store.
LoadCommitByHash(hash [32]byte) (*types.Commit, error)

Expand Down
1 change: 1 addition & 0 deletions testutil/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ func GenerateStateWithSequencer(initialHeight int64, lastBlockHeight int64, pubk
[]string{GenerateSettlementAddress()},
))
s.SetHeight(uint64(lastBlockHeight))
s.SetLastBlockTime(time.Now())
return s
}

Expand Down
3 changes: 1 addition & 2 deletions types/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ type State struct {

// Last block time
LastBlockTime atomic.Uint64 // time in tai64 format
// Last submitted block time
LastSettlementBlockTime atomic.Uint64 // time in tai64 format

}

func (s *State) GetProposer() *Sequencer {
Expand Down

0 comments on commit 7e07813

Please sign in to comment.