Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: trezor/blockbook
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 55f1bba5b7f7eac53df23ed39d3a74d73cd51f80
Choose a base ref
..
head repository: trezor/blockbook
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f22919d330f272ae080be22379885bad91d131ba
Choose a head ref
Showing with 61 additions and 2 deletions.
  1. +1 −1 blockbook.go
  2. +60 −1 db/rocksdb_ethereumtype.go
2 changes: 1 addition & 1 deletion blockbook.go
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ var (
dbPath = flag.String("datadir", "./data", "path to database directory")
dbCache = flag.Int("dbcache", 1<<29, "size of the rocksdb cache")
dbMaxOpenFiles = flag.Int("dbmaxopenfiles", 1<<14, "max open files by rocksdb")
dbMaxAddrContracts = flag.Int("dbmaxaddrcontracts", 1<<10, "max size of the address contracts map")
dbMaxAddrContracts = flag.Int("dbmaxaddrcontracts", 1<<20, "max size of the address contracts map")

blockFrom = flag.Int("blockheight", -1, "height of the starting block")
blockUntil = flag.Int("blockuntil", -1, "height of the final block")
61 changes: 60 additions & 1 deletion db/rocksdb_ethereumtype.go
Original file line number Diff line number Diff line change
@@ -163,7 +163,7 @@ func unpackAddrContracts(buf []byte, addrDesc bchain.AddressDescriptor) (*AddrCo
pt := &eth.ProtoAddrContracts{}
err := proto.Unmarshal(buf, pt)
if err != nil {
return nil, errors.New("Invalid data stored in cfAddressContracts for AddrDesc " + addrDesc.String())
return unpackAddrContractsLegacy(buf, addrDesc)
}
contracts := make([]AddrContract, len(pt.Contracts))
for i, c := range pt.Contracts {
@@ -196,6 +196,65 @@ func unpackAddrContracts(buf []byte, addrDesc bchain.AddressDescriptor) (*AddrCo
return acs, nil
}

// unpackAddrContractsLegacy unpacks AddrContracts from legacy manual packed byte slice
func unpackAddrContractsLegacy(buf []byte, addrDesc bchain.AddressDescriptor) (*AddrContracts, error) {
tt, l := unpackVaruint(buf)
buf = buf[l:]
nct, l := unpackVaruint(buf)
buf = buf[l:]
ict, l := unpackVaruint(buf)
buf = buf[l:]
c := make([]AddrContract, 0, 4)
for len(buf) > 0 {
if len(buf) < eth.EthereumTypeAddressDescriptorLen {
return nil, errors.New("Invalid data stored in cfAddressContracts for AddrDesc " + addrDesc.String())
}
contract := append(bchain.AddressDescriptor(nil), buf[:eth.EthereumTypeAddressDescriptorLen]...)
txs, l := unpackVaruint(buf[eth.EthereumTypeAddressDescriptorLen:])
buf = buf[eth.EthereumTypeAddressDescriptorLen+l:]
ttt := bchain.TokenType(txs & 3)
txs >>= 2
ac := AddrContract{
Type: ttt,
Contract: contract,
Txs: txs,
}
if ttt == bchain.FungibleToken {
b, ll := unpackBigint(buf)
buf = buf[ll:]
ac.Value = b
} else {
len, ll := unpackVaruint(buf)
buf = buf[ll:]
if ttt == bchain.NonFungibleToken {
ac.Ids = make(Ids, len)
for i := uint(0); i < len; i++ {
b, ll := unpackBigint(buf)
buf = buf[ll:]
ac.Ids[i] = b
}
} else {
ac.MultiTokenValues = make(MultiTokenValues, len)
for i := uint(0); i < len; i++ {
b, ll := unpackBigint(buf)
buf = buf[ll:]
ac.MultiTokenValues[i].Id = b
b, ll = unpackBigint(buf)
buf = buf[ll:]
ac.MultiTokenValues[i].Value = b
}
}
}
c = append(c, ac)
}
return &AddrContracts{
TotalTxs: tt,
NonContractTxs: nct,
InternalTxs: ict,
Contracts: c,
}, nil
}

func (d *RocksDB) storeAddressContracts(wb *grocksdb.WriteBatch, acm map[string]*AddrContracts) error {
for addrDesc, acs := range acm {
// address with 0 contracts is removed from db - happens on disconnect