Skip to content

Commit

Permalink
fix dev node genesis AppState
Browse files Browse the repository at this point in the history
  • Loading branch information
piux2 committed Sep 28, 2024
1 parent e7cf296 commit 7696e58
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion contribs/gnodev/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gnolang/gno/contribs/gnodev

go 1.22
go 1.22.0

replace github.com/gnolang/gno => ../..

Expand Down
23 changes: 9 additions & 14 deletions contribs/gnodev/pkg/dev/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,9 @@ func NewDevNode(ctx context.Context, cfg *NodeConfig) (*Node, error) {
initialState: cfg.InitialTxs,
currentStateIndex: len(cfg.InitialTxs),
}

// generate genesis state
genesis := gnoland.GnoGenesisState{
Balances: cfg.BalancesList,
Txs: append(pkgsTxs, cfg.InitialTxs...),
}
genesis := gnoland.DefaultGenState()
genesis.Balances = cfg.BalancesList
genesis.Txs = append(pkgsTxs, cfg.InitialTxs...)

if err := devnode.rebuildNode(ctx, genesis); err != nil {
return nil, fmt.Errorf("unable to initialize the node: %w", err)
Expand Down Expand Up @@ -270,10 +267,9 @@ func (n *Node) Reset(ctx context.Context) error {

// Append initialTxs
txs := append(pkgsTxs, n.initialState...)
genesis := gnoland.GnoGenesisState{
Balances: n.config.BalancesList,
Txs: txs,
}
genesis := gnoland.DefaultGenState()
genesis.Balances = n.config.BalancesList
genesis.Txs = txs

// Reset the node with the new genesis state.
err = n.rebuildNode(ctx, genesis)
Expand Down Expand Up @@ -410,10 +406,9 @@ func (n *Node) rebuildNodeFromState(ctx context.Context) error {
}

// Create genesis with loaded pkgs + previous state
genesis := gnoland.GnoGenesisState{
Balances: n.config.BalancesList,
Txs: append(pkgsTxs, state...),
}
genesis := gnoland.DefaultGenState()
genesis.Balances = n.config.BalancesList
genesis.Txs = append(pkgsTxs, state...)

// Reset the node with the new genesis state.
err = n.rebuildNode(ctx, genesis)
Expand Down
16 changes: 8 additions & 8 deletions contribs/gnodev/pkg/dev/node_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ func (n *Node) MoveBy(ctx context.Context, x int) error {
newState := n.state[:newIndex]

// Create genesis with loaded pkgs + previous state
genesis := gnoland.GnoGenesisState{
Balances: n.config.BalancesList,
Txs: append(pkgsTxs, newState...),
}
genesis := gnoland.DefaultGenState()
genesis.Balances = n.config.BalancesList
genesis.Txs = append(pkgsTxs, newState...)

// Reset the node with the new genesis state.
if err = n.rebuildNode(ctx, genesis); err != nil {
Expand Down Expand Up @@ -133,10 +132,11 @@ func (n *Node) ExportStateAsGenesis(ctx context.Context) (*bft.GenesisDoc, error

// Get current blockstore state
doc := *n.Node.GenesisDoc() // copy doc
doc.AppState = gnoland.GnoGenesisState{
Balances: n.config.BalancesList,
Txs: state,
}

genState := doc.AppState.(gnoland.GnoGenesisState)
genState.Balances = n.config.BalancesList
genState.Txs = state
doc.AppState = genState

return &doc, nil
}

0 comments on commit 7696e58

Please sign in to comment.