Skip to content

Commit 5c00ed9

Browse files
committed
Cleanup
1 parent 5f20efe commit 5c00ed9

File tree

98 files changed

+2126
-1038
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+2126
-1038
lines changed

accounts/abi/abi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (abi ABI) getArguments(name string, data []byte) (Arguments, error) {
105105
args = event.Inputs
106106
}
107107
if args == nil {
108-
return nil, errors.New("abi: could not locate named method or event")
108+
return nil, fmt.Errorf("abi: could not locate named method or event: %s", name)
109109
}
110110
return args, nil
111111
}

accounts/abi/bind/backends/simulated.go

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ type SimulatedBackend struct {
9797
acceptedBlock *types.Block // Currently accepted block that will be imported on request
9898
acceptedState *state.StateDB // Currently accepted state that will be the active on request
9999

100-
events *filters.EventSystem // Event system for filtering log events live
100+
events *filters.EventSystem // for filtering log events live
101+
filterSystem *filters.FilterSystem // for filtering database logs
101102

102103
config *params.ChainConfig
103104
}
@@ -118,7 +119,11 @@ func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.Genesis
118119
blockchain: blockchain,
119120
config: genesis.Config,
120121
}
121-
backend.events = filters.NewEventSystem(&filterBackend{database, blockchain, backend}, false)
122+
123+
filterBackend := &filterBackend{database, blockchain, backend}
124+
backend.filterSystem = filters.NewFilterSystem(filterBackend, filters.Config{})
125+
backend.events = filters.NewEventSystem(backend.filterSystem, false)
126+
122127
backend.rollback(blockchain.CurrentBlock())
123128
return backend
124129
}
@@ -647,7 +652,7 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call interfaces.Cal
647652
// User specified the legacy gas field, convert to 1559 gas typing
648653
call.GasFeeCap, call.GasTipCap = call.GasPrice, call.GasPrice
649654
} else {
650-
// User specified 1559 gas feilds (or none), use those
655+
// User specified 1559 gas fields (or none), use those
651656
if call.GasFeeCap == nil {
652657
call.GasFeeCap = new(big.Int)
653658
}
@@ -729,7 +734,7 @@ func (b *SimulatedBackend) FilterLogs(ctx context.Context, query interfaces.Filt
729734
var filter *filters.Filter
730735
if query.BlockHash != nil {
731736
// Block filter requested, construct a single-shot filter
732-
filter = filters.NewBlockFilter(&filterBackend{b.database, b.blockchain, b}, *query.BlockHash, query.Addresses, query.Topics)
737+
filter = b.filterSystem.NewBlockFilter(*query.BlockHash, query.Addresses, query.Topics)
733738
} else {
734739
// Initialize unset filter boundaries to run from genesis to chain head
735740
from := int64(0)
@@ -741,7 +746,7 @@ func (b *SimulatedBackend) FilterLogs(ctx context.Context, query interfaces.Filt
741746
to = query.ToBlock.Int64()
742747
}
743748
// Construct the range filter
744-
filter, _ = filters.NewRangeFilter(&filterBackend{b.database, b.blockchain, b}, from, to, query.Addresses, query.Topics)
749+
filter, _ = b.filterSystem.NewRangeFilter(from, to, query.Addresses, query.Topics)
745750
}
746751
// Run the filter and return all the logs
747752
logs, err := filter.Logs(ctx)
@@ -891,7 +896,8 @@ func (fb *filterBackend) GetMaxBlocksPerRequest() int64 {
891896
return eth.DefaultSettings.MaxBlocksPerRequest
892897
}
893898

894-
func (fb *filterBackend) ChainDb() ethdb.Database { return fb.db }
899+
func (fb *filterBackend) ChainDb() ethdb.Database { return fb.db }
900+
895901
func (fb *filterBackend) EventMux() *event.TypeMux { panic("not supported") }
896902

897903
func (fb *filterBackend) HeaderByNumber(ctx context.Context, block rpc.BlockNumber) (*types.Header, error) {
@@ -913,19 +919,8 @@ func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash) (typ
913919
return rawdb.ReadReceipts(fb.db, hash, *number, fb.bc.Config()), nil
914920
}
915921

916-
func (fb *filterBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error) {
917-
number := rawdb.ReadHeaderNumber(fb.db, hash)
918-
if number == nil {
919-
return nil, nil
920-
}
921-
receipts := rawdb.ReadReceipts(fb.db, hash, *number, fb.bc.Config())
922-
if receipts == nil {
923-
return nil, nil
924-
}
925-
logs := make([][]*types.Log, len(receipts))
926-
for i, receipt := range receipts {
927-
logs[i] = receipt.Logs
928-
}
922+
func (fb *filterBackend) GetLogs(ctx context.Context, hash common.Hash, number uint64) ([][]*types.Log, error) {
923+
logs := rawdb.ReadLogs(fb.db, hash, number)
929924
return logs, nil
930925
}
931926

accounts/abi/reflect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func mustArrayToByteSlice(value reflect.Value) reflect.Value {
109109
func set(dst, src reflect.Value) error {
110110
dstType, srcType := dst.Type(), src.Type()
111111
switch {
112-
case dstType.Kind() == reflect.Interface && dst.Elem().IsValid():
112+
case dstType.Kind() == reflect.Interface && dst.Elem().IsValid() && (dst.Elem().Type().Kind() == reflect.Ptr || dst.Elem().CanSet()):
113113
return set(dst.Elem(), src)
114114
case dstType.Kind() == reflect.Ptr && dstType.Elem() != reflect.TypeOf(big.Int{}):
115115
return set(dst.Elem(), src)

accounts/abi/reflect_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type reflectTest struct {
4242

4343
var reflectTests = []reflectTest{
4444
{
45-
name: "OneToOneCorrespondance",
45+
name: "OneToOneCorrespondence",
4646
args: []string{"fieldA"},
4747
struc: struct {
4848
FieldA int `abi:"fieldA"`

accounts/abi/unpack_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ func TestMethodMultiReturn(t *testing.T) {
362362
&[]interface{}{&expected.Int, &expected.String},
363363
"",
364364
"Can unpack into a slice",
365+
}, {
366+
&[]interface{}{&bigint, ""},
367+
&[]interface{}{&expected.Int, expected.String},
368+
"",
369+
"Can unpack into a slice without indirection",
365370
}, {
366371
&[2]interface{}{&bigint, new(string)},
367372
&[2]interface{}{&expected.Int, &expected.String},

accounts/keystore/account_cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ func TestUpdatedKeyfileContents(t *testing.T) {
329329
t.Skip("FLAKY")
330330
t.Parallel()
331331

332-
// Create a temporary kesytore to test with
332+
// Create a temporary keystore to test with
333333
rand.Seed(time.Now().UnixNano())
334334
dir := filepath.Join(os.TempDir(), fmt.Sprintf("eth-keystore-watch-test-%d-%d", os.Getpid(), rand.Int()))
335335
ks := NewKeyStore(dir, LightScryptN, LightScryptP)

accounts/keystore/file_cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type fileCache struct {
4949
func (fc *fileCache) scan(keyDir string) (mapset.Set, mapset.Set, mapset.Set, error) {
5050
t0 := time.Now()
5151

52-
// List all the failes from the keystore folder
52+
// List all the files from the keystore folder
5353
files, err := os.ReadDir(keyDir)
5454
if err != nil {
5555
return nil, nil, nil, err
@@ -71,7 +71,7 @@ func (fc *fileCache) scan(keyDir string) (mapset.Set, mapset.Set, mapset.Set, er
7171
log.Trace("Ignoring file on account scan", "path", path)
7272
continue
7373
}
74-
// Gather the set of all and fresly modified files
74+
// Gather the set of all and freshly modified files
7575
all.Add(path)
7676

7777
info, err := fi.Info()

accounts/keystore/keystore_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func TestSignRace(t *testing.T) {
224224
// Tests that the wallet notifier loop starts and stops correctly based on the
225225
// addition and removal of wallet event subscriptions.
226226
func TestWalletNotifierLifecycle(t *testing.T) {
227-
// Create a temporary kesytore to test with
227+
// Create a temporary keystore to test with
228228
_, ks := tmpKeyStore(t, false)
229229

230230
// Ensure that the notification updater is not running yet

core/blockchain.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,10 @@ func (bc *BlockChain) Stop() {
710710
log.Error("Failed to Shutdown state manager", "err", err)
711711
}
712712
log.Info("State manager shut down", "t", time.Since(start))
713+
// Flush the collected preimages to disk
714+
if err := bc.stateCache.TrieDB().CommitPreimages(); err != nil {
715+
log.Error("Failed to commit trie preimages", "err", err)
716+
}
713717

714718
// Stop senderCacher's goroutines
715719
log.Info("Shutting down sender cacher")
@@ -884,7 +888,7 @@ func (bc *BlockChain) newTip(block *types.Block) bool {
884888
// writeBlockAndSetHead expects to be the last verification step during InsertBlock
885889
// since it creates a reference that will only be cleaned up by Accept/Reject.
886890
func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB) error {
887-
if err := bc.writeBlockWithState(block, receipts, logs, state); err != nil {
891+
if err := bc.writeBlockWithState(block, receipts, state); err != nil {
888892
return err
889893
}
890894

@@ -901,7 +905,7 @@ func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types
901905

902906
// writeBlockWithState writes the block and all associated state to the database,
903907
// but it expects the chain mutex to be held.
904-
func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB) error {
908+
func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.Receipt, state *state.StateDB) error {
905909
// Irrelevant of the canonical status, write the block itself to the database.
906910
//
907911
// Note all the components of block(hash->number map, header, body, receipts)
@@ -1309,7 +1313,7 @@ func (bc *BlockChain) reportBlock(block *types.Block, receipts types.Receipts, e
13091313
i, receipt.CumulativeGasUsed, receipt.GasUsed, receipt.ContractAddress.Hex(),
13101314
receipt.Status, receipt.TxHash.Hex(), receipt.Logs, receipt.Bloom, receipt.PostState)
13111315
}
1312-
log.Error(fmt.Sprintf(`
1316+
log.Debug(fmt.Sprintf(`
13131317
########## BAD BLOCK #########
13141318
Chain config: %v
13151319
@@ -1531,7 +1535,7 @@ func (bc *BlockChain) reprocessState(current *types.Block, reexec uint64) error
15311535
// Flatten snapshot if initialized, holding a reference to the state root until the next block
15321536
// is processed.
15331537
if err := bc.flattenSnapshot(func() error {
1534-
triedb.Reference(root, common.Hash{}, true)
1538+
triedb.Reference(root, common.Hash{})
15351539
if previousRoot != (common.Hash{}) {
15361540
triedb.Dereference(previousRoot)
15371541
}

core/blockchain_reader.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ func (bc *BlockChain) HasBlock(hash common.Hash, number uint64) bool {
100100
if bc.blockCache.Contains(hash) {
101101
return true
102102
}
103+
if !bc.HasHeader(hash, number) {
104+
return false
105+
}
103106
return rawdb.HasBody(bc.db, hash, number)
104107
}
105108

0 commit comments

Comments
 (0)