Skip to content

Commit

Permalink
new skey claculatuin
Browse files Browse the repository at this point in the history
  • Loading branch information
srene committed Nov 8, 2024
1 parent 3e92814 commit 8f7c678
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion 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 @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions block/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions types/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[:],
Expand Down Expand Up @@ -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
}

Expand Down
11 changes: 11 additions & 0 deletions types/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"sync/atomic"
"time"

// TODO(tzdybal): copy to local project?

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8f7c678

Please sign in to comment.