Repository navigation
Add config to enable lattice hash #3043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,12 +32,15 @@ type StateCommitConfig struct { | |
| // WriteMode defines the write routing mode for EVM data | ||
| // Valid values: cosmos_only, dual_write, split_write, evm_only | ||
| // defaults to cosmos_only | ||
| WriteMode WriteMode `mapstructure:"write_mode"` | ||
| WriteMode WriteMode `mapstructure:"write-mode"` | ||
|
|
||
| // ReadMode defines the read routing mode for EVM data | ||
| // Valid values: cosmos_only, evm_first, split_read | ||
| // defaults to cosmos_only | ||
| ReadMode ReadMode `mapstructure:"read_mode"` | ||
| ReadMode ReadMode `mapstructure:"read-mode"` | ||
|
|
||
| // EnableLatticeHash controls whether lattice hash will be participating in final app hash or not | ||
| EnableLatticeHash bool `mapstructure:"enable-lattice-hash"` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Data format: EnableLatticeHash bool other fields:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, will fix |
||
|
|
||
| // MemIAVLConfig is the configuration for the MemIAVL (Cosmos) backend | ||
| MemIAVLConfig memiavl.Config | ||
|
|
@@ -59,11 +62,12 @@ type StateCommitConfig struct { | |
| // DefaultStateCommitConfig returns the default StateCommitConfig | ||
| func DefaultStateCommitConfig() StateCommitConfig { | ||
| return StateCommitConfig{ | ||
| Enable: true, | ||
| WriteMode: CosmosOnlyWrite, | ||
| ReadMode: CosmosOnlyRead, | ||
| MemIAVLConfig: memiavl.DefaultConfig(), | ||
| FlatKVConfig: flatkv.DefaultConfig(), | ||
| Enable: true, | ||
| WriteMode: CosmosOnlyWrite, | ||
| ReadMode: CosmosOnlyRead, | ||
| EnableLatticeHash: false, | ||
| MemIAVLConfig: memiavl.DefaultConfig(), | ||
| FlatKVConfig: flatkv.DefaultConfig(), | ||
|
|
||
| HistoricalProofMaxInFlight: DefaultSCHistoricalProofMaxInFlight, | ||
| HistoricalProofRateLimit: DefaultSCHistoricalProofRateLimit, | ||
|
|
@@ -74,10 +78,10 @@ func DefaultStateCommitConfig() StateCommitConfig { | |
| // Validate checks if the StateCommitConfig is valid | ||
| func (c StateCommitConfig) Validate() error { | ||
| if !c.WriteMode.IsValid() { | ||
| return fmt.Errorf("invalid write_mode: %s", c.WriteMode) | ||
| return fmt.Errorf("invalid write-mode: %s", c.WriteMode) | ||
| } | ||
| if !c.ReadMode.IsValid() { | ||
| return fmt.Errorf("invalid read_mode: %s", c.ReadMode) | ||
| return fmt.Errorf("invalid read-mode: %s", c.ReadMode) | ||
| } | ||
| return nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -219,16 +219,44 @@ func (cs *CompositeCommitStore) GetEarliestVersion() (int64, error) { | |
| return cs.cosmosCommitter.GetEarliestVersion() | ||
| } | ||
|
|
||
| // appendEvmLatticeHash returns a new CommitInfo with the EVM lattice hash | ||
| // appended, without mutating the original. Returns the original unchanged | ||
| // when lattice hashing is disabled. | ||
| func (cs *CompositeCommitStore) appendEvmLatticeHash(ci *proto.CommitInfo, evmHash []byte) *proto.CommitInfo { | ||
| if !cs.config.EnableLatticeHash { | ||
| return ci | ||
| } | ||
| combined := make([]proto.StoreInfo, len(ci.StoreInfos)+1) | ||
| copy(combined, ci.StoreInfos) | ||
| combined[len(combined)-1] = proto.StoreInfo{ | ||
| Name: "evm_lattice", | ||
| CommitId: proto.CommitID{ | ||
| Version: ci.Version, | ||
| Hash: evmHash, | ||
| }, | ||
| } | ||
| return &proto.CommitInfo{ | ||
| Version: ci.Version, | ||
| StoreInfos: combined, | ||
| } | ||
| } | ||
|
|
||
| // WorkingCommitInfo returns the working commit info | ||
| func (cs *CompositeCommitStore) WorkingCommitInfo() *proto.CommitInfo { | ||
| // TODO: Need to combine hash for cosmos and evm | ||
| return cs.cosmosCommitter.WorkingCommitInfo() | ||
| ci := cs.cosmosCommitter.WorkingCommitInfo() | ||
| if cs.evmCommitter != nil { | ||
| return cs.appendEvmLatticeHash(ci, cs.evmCommitter.RootHash()) | ||
| } | ||
| return ci | ||
| } | ||
|
|
||
| // LastCommitInfo returns the last commit info | ||
| func (cs *CompositeCommitStore) LastCommitInfo() *proto.CommitInfo { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some code duplication between WorkingCommitInfo and LastCommitInfo, consider extract a helper?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will look into that, good suggestion! |
||
| // TODO: Need to combine hash for cosmos and evm | ||
| return cs.cosmosCommitter.LastCommitInfo() | ||
| ci := cs.cosmosCommitter.LastCommitInfo() | ||
| if cs.evmCommitter != nil { | ||
| return cs.appendEvmLatticeHash(ci, cs.evmCommitter.CommittedRootHash()) | ||
| } | ||
| return ci | ||
| } | ||
|
|
||
| // GetChildStoreByName returns the underlying child store by module name. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting EnableLatticeHash = true with WriteMode = CosmosOnlyWrite is a silent no-op because evmCommitter is nil. The Validate() method can catch this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but I think this is probably fine, we don't have to panic here. EnableLatticeHash only take effects when FlatKV is being used, which is expected.