forked from TrueCloudLab/neoneo-go
core/state: merge spent and unspent coins state, use it to store more things
This change reduces pressure on DB by doing the following things: * not storing additional KV pair for SpentCoin * storing Output right in the UnspentCoin, thus eliminating the need to get a full transaction from DB At the same time it makes UnspentCoin more fat and hot, but it should probably worth it. Also drop `GetUnspentCoinStateOrNew` as it shouldn't ever existed, UTXOs can't come out of nowhere. 1.5M block import time (VerifyBlocks disabled) on AMD Ryzen 5 1600/16GB/HDD, before: real 302m9.895s user 96m17.200s sys 13m37.084s after: real 159m16.551s user 69m58.279s sys 7m34.334s So it's almost two-fold which is a great improvement.
This commit is contained in:
parent
e1f194ea7b
commit
23464401bc
7 changed files with 117 additions and 278 deletions
|
@ -3,18 +3,44 @@ package state
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/internal/random"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDecodeEncodeUnspentCoin(t *testing.T) {
|
||||
unspent := &UnspentCoin{
|
||||
States: []Coin{
|
||||
CoinConfirmed,
|
||||
CoinSpent,
|
||||
CoinSpent,
|
||||
CoinSpent,
|
||||
CoinConfirmed,
|
||||
Height: 100500,
|
||||
States: []OutputState{
|
||||
{
|
||||
Output: transaction.Output{
|
||||
AssetID: random.Uint256(),
|
||||
Amount: util.Fixed8(42),
|
||||
ScriptHash: random.Uint160(),
|
||||
},
|
||||
SpendHeight: 201000,
|
||||
State: CoinSpent,
|
||||
},
|
||||
{
|
||||
Output: transaction.Output{
|
||||
AssetID: random.Uint256(),
|
||||
Amount: util.Fixed8(420),
|
||||
ScriptHash: random.Uint160(),
|
||||
},
|
||||
SpendHeight: 0,
|
||||
State: CoinConfirmed,
|
||||
},
|
||||
{
|
||||
Output: transaction.Output{
|
||||
AssetID: random.Uint256(),
|
||||
Amount: util.Fixed8(4200),
|
||||
ScriptHash: random.Uint160(),
|
||||
},
|
||||
SpendHeight: 111000,
|
||||
State: CoinSpent & CoinClaimed,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue