Skip to content

Commit

Permalink
debug: check the modifications of accounts in MPT.
Browse files Browse the repository at this point in the history
  • Loading branch information
iiinotlll committed Nov 14, 2024
1 parent 0a58610 commit 1fcbec0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
Binary file removed blockEmulator_Linux_Precompile
Binary file not shown.
Binary file removed blockEmulator_MacOS_Precompile
Binary file not shown.
Binary file removed blockEmulator_Windows_Precompile.exe
Binary file not shown.
21 changes: 13 additions & 8 deletions chain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,21 @@ func (bc *BlockChain) AddAccounts(ac []string, as []*core.AccountState, miner in
st.Update([]byte(addr), new_state.Encode())
}
}

rrt, ns := st.Commit(false)
err = bc.triedb.Update(trie.NewWithNodeSet(ns))
if err != nil {
log.Panic(err)
}
err = bc.triedb.Commit(rrt, false)
if err != nil {
log.Panic(err)

// if `ns` is nil, the `err = bc.triedb.Update(trie.NewWithNodeSet(ns))` will report an error.
if ns != nil {
err = bc.triedb.Update(trie.NewWithNodeSet(ns))
if err != nil {
log.Panic(err)
}
err = bc.triedb.Commit(rrt, false)
if err != nil {
log.Panic(err)
}
rt = rrt.Bytes()
}
rt = rrt.Bytes()
}

emptyTxs := make([]*core.Transaction, 0)
Expand Down
5 changes: 5 additions & 0 deletions chain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func TestBlockChain(t *testing.T) {
CurChain.AddAccounts(accounts, as, 0)
CurChain.PrintBlockChain()

// add the same account.
CurChain.AddAccounts([]string{accounts[0]}, []*core.AccountState{as[0]}, 0)
CurChain.PrintBlockChain()

astates := CurChain.FetchAccounts(accounts)
for idx, state := range astates {
fmt.Println(accounts[idx], state.Balance)
Expand All @@ -54,4 +58,5 @@ func TestBlockChain(t *testing.T) {
fmt.Printf("Failed to delete directory: %v\n", err)
return
}
fmt.Printf("Done")
}

0 comments on commit 1fcbec0

Please sign in to comment.