Check the order of utxos
parent
2e37cbb974
commit
d583028721
|
@ -1477,7 +1477,7 @@ func (d *RocksDB) disconnectBlock(height uint32, blockTxs []blockTxs) error {
|
||||||
sBtxID := string(btxID)
|
sBtxID := string(btxID)
|
||||||
a, exist := blockAddressesTxs[sAddrDesc]
|
a, exist := blockAddressesTxs[sAddrDesc]
|
||||||
if !exist {
|
if !exist {
|
||||||
blockAddressesTxs[sAddrDesc] = map[string]struct{}{sBtxID: struct{}{}}
|
blockAddressesTxs[sAddrDesc] = map[string]struct{}{sBtxID: {}}
|
||||||
} else {
|
} else {
|
||||||
_, exist = a[sBtxID]
|
_, exist = a[sBtxID]
|
||||||
if !exist {
|
if !exist {
|
||||||
|
@ -1851,8 +1851,16 @@ func (d *RocksDB) ComputeInternalStateColumnStats(stopCompute chan os.Signal) er
|
||||||
|
|
||||||
func (d *RocksDB) fixUtxo(addrDesc bchain.AddressDescriptor, ba *AddrBalance) (bool, error) {
|
func (d *RocksDB) fixUtxo(addrDesc bchain.AddressDescriptor, ba *AddrBalance) (bool, error) {
|
||||||
var checksum big.Int
|
var checksum big.Int
|
||||||
|
var prevUtxo *Utxo
|
||||||
for i := range ba.Utxos {
|
for i := range ba.Utxos {
|
||||||
checksum.Add(&checksum, &ba.Utxos[i].ValueSat)
|
utxo := &ba.Utxos[i]
|
||||||
|
checksum.Add(&checksum, &utxo.ValueSat)
|
||||||
|
if prevUtxo != nil {
|
||||||
|
if prevUtxo.Vout > utxo.Vout && *(*int)(unsafe.Pointer(&utxo.BtxID[0])) == *(*int)(unsafe.Pointer(&prevUtxo.BtxID[0])) && bytes.Equal(utxo.BtxID, prevUtxo.BtxID) {
|
||||||
|
glog.Error("FixUtxo: addrDesc ", addrDesc, ", needs reorder")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prevUtxo = utxo
|
||||||
}
|
}
|
||||||
if checksum.Cmp(&ba.BalanceSat) != 0 {
|
if checksum.Cmp(&ba.BalanceSat) != 0 {
|
||||||
var checksumFromTxs big.Int
|
var checksumFromTxs big.Int
|
||||||
|
|
|
@ -1148,19 +1148,19 @@ func TestAddrBalance_utxo_methods(t *testing.T) {
|
||||||
SentSat: *big.NewInt(10000),
|
SentSat: *big.NewInt(10000),
|
||||||
BalanceSat: *big.NewInt(1000),
|
BalanceSat: *big.NewInt(1000),
|
||||||
Utxos: []Utxo{
|
Utxos: []Utxo{
|
||||||
Utxo{
|
{
|
||||||
BtxID: hexToBytes(dbtestdata.TxidB1T1),
|
BtxID: hexToBytes(dbtestdata.TxidB1T1),
|
||||||
Vout: 1,
|
Vout: 1,
|
||||||
Height: 5000,
|
Height: 5000,
|
||||||
ValueSat: *big.NewInt(100),
|
ValueSat: *big.NewInt(100),
|
||||||
},
|
},
|
||||||
Utxo{
|
{
|
||||||
BtxID: hexToBytes(dbtestdata.TxidB1T1),
|
BtxID: hexToBytes(dbtestdata.TxidB1T1),
|
||||||
Vout: 4,
|
Vout: 4,
|
||||||
Height: 5000,
|
Height: 5000,
|
||||||
ValueSat: *big.NewInt(100),
|
ValueSat: *big.NewInt(100),
|
||||||
},
|
},
|
||||||
Utxo{
|
{
|
||||||
BtxID: hexToBytes(dbtestdata.TxidB1T2),
|
BtxID: hexToBytes(dbtestdata.TxidB1T2),
|
||||||
Vout: 0,
|
Vout: 0,
|
||||||
Height: 5001,
|
Height: 5001,
|
||||||
|
@ -1208,49 +1208,49 @@ func TestAddrBalance_utxo_methods(t *testing.T) {
|
||||||
SentSat: *big.NewInt(10000),
|
SentSat: *big.NewInt(10000),
|
||||||
BalanceSat: *big.NewInt(1000),
|
BalanceSat: *big.NewInt(1000),
|
||||||
Utxos: []Utxo{
|
Utxos: []Utxo{
|
||||||
Utxo{
|
{
|
||||||
BtxID: hexToBytes(dbtestdata.TxidB1T1),
|
BtxID: hexToBytes(dbtestdata.TxidB1T1),
|
||||||
Vout: 0,
|
Vout: 0,
|
||||||
Height: 5000,
|
Height: 5000,
|
||||||
ValueSat: *big.NewInt(100),
|
ValueSat: *big.NewInt(100),
|
||||||
},
|
},
|
||||||
Utxo{
|
{
|
||||||
BtxID: hexToBytes(dbtestdata.TxidB1T1),
|
BtxID: hexToBytes(dbtestdata.TxidB1T1),
|
||||||
Vout: 1,
|
Vout: 1,
|
||||||
Height: 5000,
|
Height: 5000,
|
||||||
ValueSat: *big.NewInt(100),
|
ValueSat: *big.NewInt(100),
|
||||||
},
|
},
|
||||||
Utxo{
|
{
|
||||||
BtxID: hexToBytes(dbtestdata.TxidB1T1),
|
BtxID: hexToBytes(dbtestdata.TxidB1T1),
|
||||||
Vout: 2,
|
Vout: 2,
|
||||||
Height: 5000,
|
Height: 5000,
|
||||||
ValueSat: *big.NewInt(100),
|
ValueSat: *big.NewInt(100),
|
||||||
},
|
},
|
||||||
Utxo{
|
{
|
||||||
BtxID: hexToBytes(dbtestdata.TxidB1T1),
|
BtxID: hexToBytes(dbtestdata.TxidB1T1),
|
||||||
Vout: 4,
|
Vout: 4,
|
||||||
Height: 5000,
|
Height: 5000,
|
||||||
ValueSat: *big.NewInt(100),
|
ValueSat: *big.NewInt(100),
|
||||||
},
|
},
|
||||||
Utxo{
|
{
|
||||||
BtxID: hexToBytes(dbtestdata.TxidB1T1),
|
BtxID: hexToBytes(dbtestdata.TxidB1T1),
|
||||||
Vout: 10,
|
Vout: 10,
|
||||||
Height: 5000,
|
Height: 5000,
|
||||||
ValueSat: *big.NewInt(100),
|
ValueSat: *big.NewInt(100),
|
||||||
},
|
},
|
||||||
Utxo{
|
{
|
||||||
BtxID: hexToBytes(dbtestdata.TxidB1T2),
|
BtxID: hexToBytes(dbtestdata.TxidB1T2),
|
||||||
Vout: 0,
|
Vout: 0,
|
||||||
Height: 5001,
|
Height: 5001,
|
||||||
ValueSat: *big.NewInt(800),
|
ValueSat: *big.NewInt(800),
|
||||||
},
|
},
|
||||||
Utxo{
|
{
|
||||||
BtxID: hexToBytes(dbtestdata.TxidB2T1),
|
BtxID: hexToBytes(dbtestdata.TxidB2T1),
|
||||||
Vout: 0,
|
Vout: 0,
|
||||||
Height: 5003,
|
Height: 5003,
|
||||||
ValueSat: *big.NewInt(800),
|
ValueSat: *big.NewInt(800),
|
||||||
},
|
},
|
||||||
Utxo{
|
{
|
||||||
BtxID: hexToBytes(dbtestdata.TxidB2T1),
|
BtxID: hexToBytes(dbtestdata.TxidB2T1),
|
||||||
Vout: 1,
|
Vout: 1,
|
||||||
Height: 5003,
|
Height: 5003,
|
||||||
|
|
Loading…
Reference in New Issue