Skip to content

Commit

Permalink
update to defer func to ensure addressContracts is reset and handle p…
Browse files Browse the repository at this point in the history
…ossible error
  • Loading branch information
kaladinlight committed Nov 6, 2024
1 parent 9c8e793 commit 2c9a674
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions db/rocksdb_ethereumtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ func unpackAddrContractsLegacy(buf []byte, addrDesc bchain.AddressDescriptor) (*
}

func (d *RocksDB) storeAddressContracts(wb *grocksdb.WriteBatch, acm map[string]*AddrContracts) error {
defer func() {
if d.maxAddrContracts == 0 {
d.addressContracts = make(map[string]*AddrContracts)
}
}()
for addrDesc, acs := range acm {
// address with 0 contracts is removed from db - happens on disconnect
if acs == nil || (acs.NonContractTxs == 0 && acs.InternalTxs == 0 && len(acs.Contracts) == 0) {
Expand All @@ -315,9 +320,6 @@ func (d *RocksDB) storeAddressContracts(wb *grocksdb.WriteBatch, acm map[string]
}
}
}
if d.maxAddrContracts == 0 {
d.addressContracts = make(map[string]*AddrContracts)
}
return nil
}

Expand Down Expand Up @@ -1485,7 +1487,9 @@ func (d *RocksDB) DisconnectBlockRangeEthereumType(lower uint32, higher uint32)
wb.DeleteCF(d.cfh[cfHeight], key)
wb.DeleteCF(d.cfh[cfBlockInternalDataErrors], key)
}
d.storeAddressContracts(wb, contracts)
if err := d.storeAddressContracts(wb, contracts); err != nil {
return err
}
err := d.WriteBatch(wb)
if err == nil {
d.is.RemoveLastBlockTimes(int(higher-lower) + 1)
Expand Down

0 comments on commit 2c9a674

Please sign in to comment.