From a04e38f0f7bab2d41223534bd4bdabe43f326f3a Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Thu, 2 Aug 2018 17:46:23 +0200 Subject: [PATCH] Improve handling of invalid addresses --- db/rocksdb.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/db/rocksdb.go b/db/rocksdb.go index dc33debb..e71f79d7 100644 --- a/db/rocksdb.go +++ b/db/rocksdb.go @@ -324,7 +324,7 @@ func (d *RocksDB) writeAddressesUTXO(wb *gorocksdb.WriteBatch, block *bchain.Blo glog.Warningf("rocksdb: addrID: %v - height %d, tx %v, output %v", err, block.Height, tx.Txid, output) } } else { - glog.Infof("rocksdb: block %d, skipping addrID of length %d", block.Height, len(addrID)) + glog.Infof("rocksdb: height %d, tx %v, vout %v, skipping addrID of length %d", block.Height, tx.Txid, i, len(addrID)) } continue } @@ -397,8 +397,12 @@ func (d *RocksDB) writeAddressesUTXO(wb *gorocksdb.WriteBatch, block *bchain.Blo } tai.addrID = ot.addrID tai.valueSat = ot.valueSat - // mark the output tx as spent + // mark the output as spent in tx ot.spent = true + if len(ot.addrID) == 0 { + glog.Warningf("rocksdb: height %d, tx %v, input tx %v vout %v skipping empty address", block.Height, tx.Txid, input.Txid, input.Vout) + continue + } strAddrID := string(ot.addrID) // check that the address was used already in this block o, processed := addresses[strAddrID] @@ -428,10 +432,11 @@ func (d *RocksDB) writeAddressesUTXO(wb *gorocksdb.WriteBatch, block *bchain.Blo ab.balanceSat.Sub(&ab.balanceSat, &ot.valueSat) if ab.balanceSat.Sign() < 0 { ad, err := d.chainParser.OutputScriptToAddresses(ot.addrID) + had := hex.EncodeToString(ot.addrID) if err != nil { - glog.Warningf("rocksdb: unparsable address reached negative balance %v, resetting to 0. Parser error %v", ab.balanceSat.String(), err) + glog.Warningf("rocksdb: unparsable address hex '%v' reached negative balance %v, resetting to 0. Parser error %v", had, ab.balanceSat.String(), err) } else { - glog.Warningf("rocksdb: address %v reached negative balance %v, resetting to 0", ab.balanceSat.String(), ad) + glog.Warningf("rocksdb: address %v hex '%v' reached negative balance %v, resetting to 0", ad, had, ab.balanceSat.String()) } ab.balanceSat.SetInt64(0) }