Skip to content
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

fix: don't use rlp in the tree for slot values #51

Merged
merged 2 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,15 @@ func (s *stateObject) updateTrie(db Database) Trie {
}
s.db.StorageDeleted += 1
} else {
// Encoding []byte cannot fail, ok to ignore the error.
v, _ = rlp.EncodeToBytes(common.TrimLeftZeroes(value[:]))

if !tr.IsVerkle() {
// Encoding []byte cannot fail, ok to ignore the error.
v, _ = rlp.EncodeToBytes(common.TrimLeftZeroes(value[:]))

s.setError(tr.TryUpdate(key[:], v))
} else {
k := trieUtils.GetTreeKeyStorageSlot(s.address[:], new(uint256.Int).SetBytes(key[:]))
// Update the trie, with v as a value
s.setError(tr.TryUpdate(k, v))
s.setError(tr.TryUpdate(k, value[:]))
}
s.db.StorageUpdated += 1
}
Expand Down
23 changes: 19 additions & 4 deletions miner/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ func (b *testWorkerBackend) newRandomUncle() *types.Block {
return blocks[0]
}

func (b *testWorkerBackend) newRandomVerkleUncle() *types.Block {
var parent *types.Block
cur := b.chain.CurrentBlock()
if cur.NumberU64() == 0 {
parent = b.chain.Genesis()
} else {
parent = b.chain.GetBlockByHash(b.chain.CurrentBlock().ParentHash())
}
blocks, _ := core.GenerateVerkleChain(b.chain.Config(), parent, b.chain.Engine(), b.db, 1, func(i int, gen *core.BlockGen) {
var addr = make([]byte, common.AddressLength)
rand.Read(addr)
gen.SetCoinbase(common.BytesToAddress(addr))
})
return blocks[0]
}

func (b *testWorkerBackend) newRandomTx(creation bool) *types.Transaction {
var tx *types.Transaction
gasPrice := big.NewInt(10 * params.InitialBaseFee)
Expand Down Expand Up @@ -306,11 +322,10 @@ func TestGenerateBlocksAndImportVerkle(t *testing.T) {
w.start()

for i := 0; i < 5; i++ {
// TODO this causes a failure, but shouldn't. investigate.
//b.txPool.AddLocal(b.newRandomTx(true))
b.txPool.AddLocal(b.newRandomTx(true))
b.txPool.AddLocal(b.newRandomTx(false))
//w.postSideBlock(core.ChainSideEvent{Block: b.newRandomUncle()})
//w.postSideBlock(core.ChainSideEvent{Block: b.newRandomUncle()})
w.postSideBlock(core.ChainSideEvent{Block: b.newRandomVerkleUncle()})
w.postSideBlock(core.ChainSideEvent{Block: b.newRandomVerkleUncle()})

select {
case ev := <-sub.Chan():
Expand Down