Skip to content

Commit

Permalink
madness
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski committed Oct 22, 2024
1 parent 3820ba6 commit 722e0ee
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion server/v2/appmanager/appmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (a AppManager[T]) InitGenesis(
return blockResponse, nil, fmt.Errorf("failed to deliver block %d: %w", blockRequest.Height, err)
}

// after executing block 0, we extract the changes and apply them to the genesis state.
// after executing the genesis block, we extract the changes and apply them to the genesis state.
stateChanges, err := blockZeroState.GetStateChanges()
if err != nil {
return nil, nil, fmt.Errorf("failed to get block zero state changes: %w", err)
Expand Down
14 changes: 7 additions & 7 deletions server/v2/cometbft/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,15 @@ func (c *Consensus[T]) InitChain(ctx context.Context, req *abciproto.InitChainRe
bz := sha256.Sum256([]byte{})

br := &server.BlockRequest[T]{
Height: uint64(req.InitialHeight - 1),
Height: uint64(req.InitialHeight),
Time: req.Time,
Hash: bz[:],
AppHash: ci.Hash,
ChainId: req.ChainId,
IsGenesis: true,
}

blockresponse, genesisState, err := c.app.InitGenesis(
blockResponse, genesisState, err := c.app.InitGenesis(
ctx,
br,
req.AppStateBytes,
Expand All @@ -335,14 +335,14 @@ func (c *Consensus[T]) InitChain(ctx context.Context, req *abciproto.InitChainRe
return nil, fmt.Errorf("genesis state init failure: %w", err)
}

for _, txRes := range blockresponse.TxResults {
for _, txRes := range blockResponse.TxResults {
if err := txRes.Error; err != nil {
space, code, log := errorsmod.ABCIInfo(err, c.cfg.AppTomlConfig.Trace)
c.logger.Warn("genesis tx failed", "codespace", space, "code", code, "log", log)
space, code, txLog := errorsmod.ABCIInfo(err, c.cfg.AppTomlConfig.Trace)
c.logger.Warn("genesis tx failed", "codespace", space, "code", code, "log", txLog)
}
}

validatorUpdates := intoABCIValidatorUpdates(blockresponse.ValidatorUpdates)
validatorUpdates := intoABCIValidatorUpdates(blockResponse.ValidatorUpdates)

// set the initial version of the store
if err := c.store.SetInitialVersion(uint64(req.InitialHeight)); err != nil {
Expand All @@ -356,7 +356,7 @@ func (c *Consensus[T]) InitChain(ctx context.Context, req *abciproto.InitChainRe
cs := &store.Changeset{
Changes: stateChanges,
}
stateRoot, err := c.store.WorkingHash(cs)
stateRoot, err := c.store.Commit(cs)
if err != nil {
return nil, fmt.Errorf("unable to write the changeset: %w", err)
}
Expand Down
19 changes: 12 additions & 7 deletions store/v2/commitment/iavlv2/tree.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package iavlv2

import (
"cosmossdk.io/store/v2"
"cosmossdk.io/store/v2/commitment"
"fmt"

"github.com/cosmos/iavl/v2"
ics23 "github.com/cosmos/ics23/go"

"cosmossdk.io/store/v2"
"cosmossdk.io/store/v2/commitment"
)

var (
Expand All @@ -14,7 +16,8 @@ var (
)

type Tree struct {
tree *iavl.Tree
tree *iavl.Tree
saveErr error
}

func NewTree(treeOptions iavl.TreeOptions, dbOptions iavl.SqliteDbOptions, pool *iavl.NodePool) (*Tree, error) {
Expand Down Expand Up @@ -45,20 +48,22 @@ func (t Tree) Hash() []byte {
}

func (t Tree) WorkingHash() []byte {
return t.tree.Hash()
// iavl v2 and store/v2 have different working hash semantics so we must commit here
var hash []byte
hash, _, t.saveErr = t.tree.SaveVersion()
return hash
}

func (t Tree) LoadVersion(version uint64) error {
// TODO fix this in iavl v2
if version == 0 {
return nil
}
return t.tree.LoadVersion(int64(version + 1))
return t.tree.LoadVersion(int64(version))
}

func (t Tree) Commit() ([]byte, uint64, error) {
h, v, err := t.tree.SaveVersion()
return h, uint64(v), err
return t.tree.Hash(), uint64(t.tree.Version()), t.saveErr
}

func (t Tree) SetInitialVersion(version uint64) error {
Expand Down
2 changes: 1 addition & 1 deletion store/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/cockroachdb/pebble v1.1.0
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/gogoproto v1.7.0
github.com/cosmos/iavl v1.0.0-beta.1.0.20240813194616-eb5078efcf9e
github.com/cosmos/iavl v1.3.0
github.com/cosmos/iavl/v2 v2.0.0-20241021162339-e99f035d10e3
github.com/cosmos/ics23/go v0.11.0
github.com/google/btree v1.1.2
Expand Down
6 changes: 4 additions & 2 deletions store/v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+R
github.com/cosmos/cosmos-proto v1.0.0-beta.5/go.mod h1:hQGLpiIUloJBMdQMMWb/4wRApmI9hjHH05nefC0Ojec=
github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fro=
github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0=
github.com/cosmos/iavl v1.0.0-beta.1.0.20240813194616-eb5078efcf9e h1:LEii0v/FxtXa/F7mRn+tijZ0zaXBPn2ZkKwb6Qm4rqE=
github.com/cosmos/iavl v1.0.0-beta.1.0.20240813194616-eb5078efcf9e/go.mod h1:3ywr0wDnWeD7MUH6qu50wZ5bxuKH3LBrGG4/lZX8lVY=
github.com/cosmos/iavl v1.3.0 h1:Ezaxt8aPA3kbkhsfyqwenChGLQwHDAIif3tG9x1FMV8=
github.com/cosmos/iavl v1.3.0/go.mod h1:T6SfBcyhulVIY2G/ZtAtQm/QiJvsuhIos52V4dWYk88=
github.com/cosmos/iavl-bench/bench v0.0.4 h1:J6zQPiBqF4CXMM3QBsLqZgQEBGY0taX85vLIZMhmAfQ=
github.com/cosmos/iavl-bench/bench v0.0.4/go.mod h1:j2rLae77EffacWcp7mmj3Uaa4AOAmZA7ymvhsuBQKKI=
github.com/cosmos/iavl/v2 v2.0.0-20241021162339-e99f035d10e3 h1:hYtQI/iwLZw4dEMCnIFt1fuPsKtPD2ghUt+hdmK5zHo=
Expand Down Expand Up @@ -86,6 +86,8 @@ github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down
4 changes: 3 additions & 1 deletion store/v2/root/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ func CreateRootStore(opts *FactoryOptions) (store.RootStore, error) {
return iavl.NewIavlTree(db.NewPrefixDB(opts.SCRawDB, []byte(key)), opts.Logger, storeOpts.IavlConfig), nil
case SCTypeIavlV2:
treeOpts := libiavlv2.DefaultTreeOptions()
treeOpts.StateStorage = false
treeOpts.StateStorage = true
treeOpts.EvictionDepth = 20
treeOpts.HeightFilter = 0
dbOptions := libiavlv2.SqliteDbOptions{
Path: fmt.Sprintf("%s/data/sc/iavl-v2/%s", opts.RootDir, key),
}
Expand Down
2 changes: 1 addition & 1 deletion store/v2/root/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func (s *Store) Commit(cs *corestore.Changeset) ([]byte, error) {

// signal to the pruning manager that a new version is about to be committed
// this may be required if the SS and SC backends implementation have the
// background pruning process which must be paused during the commit
// background pruning process (iavl v1 for example) which must be paused during the commit
if err := s.pruningManager.SignalCommit(true, version); err != nil {
s.logger.Error("failed to signal commit to pruning manager", "err", err)
}
Expand Down

0 comments on commit 722e0ee

Please sign in to comment.