From 128a491ec9b3108cda59f7f788a624c26337d4bc Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Thu, 18 Jun 2026 12:18:35 +0800 Subject: [PATCH] trie/bintrie: implement updateBatch --- trie/bintrie/trie.go | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/trie/bintrie/trie.go b/trie/bintrie/trie.go index ac9b19a2e1..1652b0ecb5 100644 --- a/trie/bintrie/trie.go +++ b/trie/bintrie/trie.go @@ -452,10 +452,31 @@ func (t *BinaryTrie) Witness() map[string][]byte { return t.tracer.Values() } -func (t *BinaryTrie) UpdateStorageBatch(_ common.Address, keys [][]byte, values [][]byte) error { - panic("not implemented") +// UpdateStorageBatch updates a list of storage slots sequentially. +func (t *BinaryTrie) UpdateStorageBatch(address common.Address, keys [][]byte, values [][]byte) error { + if len(keys) != len(values) { + return fmt.Errorf("keys and values length mismatch: %d != %d", len(keys), len(values)) + } + for i, key := range keys { + if err := t.UpdateStorage(address, key, values[i]); err != nil { + return err + } + } + return nil } -func (t *BinaryTrie) UpdateAccountBatch(addresses []common.Address, accounts []*types.StateAccount, _ []int) error { - panic("not implemented") +// UpdateAccountBatch updates a list of accounts sequentially. +func (t *BinaryTrie) UpdateAccountBatch(addresses []common.Address, accounts []*types.StateAccount, codeLens []int) error { + if len(addresses) != len(accounts) { + return fmt.Errorf("addresses and accounts length mismatch: %d != %d", len(addresses), len(accounts)) + } + if len(addresses) != len(codeLens) { + return fmt.Errorf("addresses and code length mismatch: %d != %d", len(addresses), len(codeLens)) + } + for i, addr := range addresses { + if err := t.UpdateAccount(addr, accounts[i], codeLens[i]); err != nil { + return err + } + } + return nil }