From 8f7c678febf436d9b832ac0af92e29ab0182709b Mon Sep 17 00:00:00 2001 From: Sergi Rene Date: Wed, 16 Oct 2024 14:44:56 +0200 Subject: [PATCH] new skey claculatuin --- block/manager.go | 2 +- block/state.go | 4 +++- block/submit.go | 1 + config/config.go | 6 +++--- config/config_test.go | 2 +- config/defaults.go | 2 +- config/toml.go | 2 +- node/node_test.go | 2 +- types/serialization.go | 3 +++ types/state.go | 11 +++++++++++ 10 files changed, 26 insertions(+), 9 deletions(-) diff --git a/block/manager.go b/block/manager.go index 3744dc8eb..a61276ec8 100644 --- a/block/manager.go +++ b/block/manager.go @@ -284,13 +284,13 @@ func (m *Manager) updateFromLastSettlementState() error { m.LastSettlementHeight.Store(uint64(m.Genesis.InitialHeight - 1)) return nil } - if err != nil { // TODO: separate between fresh rollapp and non-registered rollapp return err } m.LastSettlementHeight.Store(latestHeight) + m.State.LastSubmittedBlockTime = res.BlockDescriptors[len(res.BlockDescriptors)-1].Timestamp if latestHeight >= m.State.NextHeight() { m.UpdateTargetHeight(latestHeight) diff --git a/block/state.go b/block/state.go index e1e850825..8b463f80e 100644 --- a/block/state.go +++ b/block/state.go @@ -4,6 +4,7 @@ import ( "bytes" "errors" "fmt" + "time" errorsmod "cosmossdk.io/errors" @@ -64,6 +65,7 @@ func NewStateFromGenesis(genDoc *tmtypes.GenesisDoc) (*types.State, error) { ConsensusParams: *genDoc.ConsensusParams, } s.SetHeight(0) + s.LastBlockTime = time.Now() copy(s.AppHash[:], genDoc.AppHash) err = s.SetRollappParamsFromGenesis(genDoc.AppState) @@ -123,7 +125,7 @@ func (e *Executor) UpdateStateAfterCommit(s *types.State, resp *tmstate.ABCIResp copy(s.LastHeaderHash[:], lastHeaderHash[:]) s.SetHeight(height) - + s.LastBlockTime = time.Now() if resp.EndBlock.ConsensusParamUpdates != nil { s.ConsensusParams.Block.MaxGas = resp.EndBlock.ConsensusParamUpdates.Block.MaxGas s.ConsensusParams.Block.MaxBytes = resp.EndBlock.ConsensusParamUpdates.Block.MaxBytes diff --git a/block/submit.go b/block/submit.go index d99b9b2fd..96a1f6316 100644 --- a/block/submit.go +++ b/block/submit.go @@ -250,6 +250,7 @@ func (m *Manager) SubmitBatch(batch *types.Batch) error { types.RollappHubHeightGauge.Set(float64(batch.EndHeight())) m.LastSettlementHeight.Store(batch.EndHeight()) + m.State.LastSubmittedBlockTime = time.Now() return nil } diff --git a/config/config.go b/config/config.go index f6f6652a9..50da40f0a 100644 --- a/config/config.go +++ b/config/config.go @@ -56,7 +56,7 @@ type BlockManagerConfig struct { // BatchSubmitMaxTime is how long should block manager wait for before submitting batch BatchSubmitTime time.Duration `mapstructure:"batch_submit_time"` // BatchSkew is the number of batches waiting to be submitted. Block production will be paused if this limit is reached. - BatchSkew time.Duration `mapstructure:"max_batch_skew"` + BatchSkew time.Duration `mapstructure:"max_skew_time"` // The size of the batch of blocks and commits in Bytes. We'll write every batch to the DA and the settlement layer. BatchSubmitBytes uint64 `mapstructure:"batch_submit_bytes"` } @@ -159,9 +159,9 @@ func (c BlockManagerConfig) Validate() error { return fmt.Errorf("batch_submit_bytes must be positive") } - if c.BatchSkew < c.BatchSubmitTime { + /*if c.BatchSkew < c.BatchSubmitTime { return fmt.Errorf("max_batch_skew cannot be less than batch_submit_time %s", c.BatchSubmitTime) - } + }*/ return nil } diff --git a/config/config_test.go b/config/config_test.go index ff9ffd7a6..f2eea6fd2 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -187,7 +187,7 @@ func fullNodeConfig() config.NodeConfig { MaxIdleTime: 20 * time.Second, MaxProofTime: 20 * time.Second, BatchSubmitTime: 20 * time.Second, - BatchSkew: 24 * time.Hour, + BatchSkew: 10, BatchSubmitBytes: 10000, }, DAConfig: "da-config", diff --git a/config/defaults.go b/config/defaults.go index c90956f3a..dd8a90dd5 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -26,7 +26,7 @@ func DefaultConfig(home string) *NodeConfig { MaxIdleTime: 3600 * time.Second, MaxProofTime: 100 * time.Second, BatchSubmitTime: 3600 * time.Second, - BatchSkew: 1 * time.Hour, + BatchSkew: 200 * time.Millisecond, BatchSubmitBytes: 500000, }, SettlementLayer: "mock", diff --git a/config/toml.go b/config/toml.go index 14e2ee800..a5d88bfe5 100644 --- a/config/toml.go +++ b/config/toml.go @@ -70,7 +70,7 @@ block_time = "{{ .BlockManagerConfig.BlockTime }}" # block production interval in case of no transactions ("0s" produces empty blocks) max_idle_time = "{{ .BlockManagerConfig.MaxIdleTime }}" max_proof_time = "{{ .BlockManagerConfig.MaxProofTime }}" -max_batch_skew = {{ .BlockManagerConfig.BatchSkew }} +max_skew_time = {{ .BlockManagerConfig.BatchSkew }} # triggers to submit batch to DA and settlement (both required) diff --git a/node/node_test.go b/node/node_test.go index ce1103ae5..57aecf762 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -78,7 +78,7 @@ func TestMempoolDirectly(t *testing.T) { BlockTime: 1 * time.Second, BatchSubmitTime: 60 * time.Second, BatchSubmitBytes: 100000, - BatchSkew: 24 * time.Hour, + BatchSkew: 10, }, DAConfig: "", SettlementLayer: "mock", diff --git a/types/serialization.go b/types/serialization.go index e90fc5785..aae805a1b 100644 --- a/types/serialization.go +++ b/types/serialization.go @@ -265,6 +265,7 @@ func (s *State) ToProto() (*pb.State, error) { ChainId: s.ChainID, InitialHeight: int64(s.InitialHeight), LastBlockHeight: int64(s.Height()), + LastBlockTime: s.LastBlockTime, ConsensusParams: s.ConsensusParams, LastResultsHash: s.LastResultsHash[:], LastHeaderHash: s.LastHeaderHash[:], @@ -296,6 +297,8 @@ func (s *State) FromProto(other *pb.State) error { copy(s.LastResultsHash[:], other.LastResultsHash) copy(s.AppHash[:], other.AppHash) s.RollappParams = other.RollappParams + s.LastBlockTime = other.LastBlockTime + return nil } diff --git a/types/state.go b/types/state.go index 529cccaa0..ed66b008c 100644 --- a/types/state.go +++ b/types/state.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "sync/atomic" + "time" // TODO(tzdybal): copy to local project? @@ -43,6 +44,12 @@ type State struct { // LastHeaderHash is the hash of the last block header. LastHeaderHash [32]byte + + // Last block time + LastBlockTime time.Time + + // Last submitted block time + LastSubmittedBlockTime time.Time } func (s *State) GetProposer() *Sequencer { @@ -98,6 +105,10 @@ func (s *State) NextHeight() uint64 { return s.Height() + 1 } +func (s *State) GetSkewTime() time.Duration { + return s.LastBlockTime.Sub(s.LastSubmittedBlockTime) +} + // SetRollappParamsFromGenesis sets the rollapp consensus params from genesis func (s *State) SetRollappParamsFromGenesis(appState json.RawMessage) error { var objmap map[string]json.RawMessage