Consolidate acct diff structs for updated & updated/deleted accts
This commit is contained in:
parent
feaff9998f
commit
74bcf49aa4
@ -145,8 +145,8 @@ func (sdb *builder) collectDiffNodes(a, b trie.NodeIterator) (map[common.Address
|
|||||||
return diffAccounts, nil
|
return diffAccounts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sdb *builder) buildDiffEventual(accounts map[common.Address]*state.Account, created bool) (map[common.Address]AccountDiffEventual, error) {
|
func (sdb *builder) buildDiffEventual(accounts map[common.Address]*state.Account, created bool) (map[common.Address]AccountDiff, error) {
|
||||||
accountDiffs := make(map[common.Address]AccountDiffEventual)
|
accountDiffs := make(map[common.Address]AccountDiff)
|
||||||
for addr, val := range accounts {
|
for addr, val := range accounts {
|
||||||
sr := val.Root
|
sr := val.Root
|
||||||
storageDiffs, err := sdb.buildStorageDiffsEventual(sr, created)
|
storageDiffs, err := sdb.buildStorageDiffsEventual(sr, created)
|
||||||
@ -160,7 +160,7 @@ func (sdb *builder) buildDiffEventual(accounts map[common.Address]*state.Account
|
|||||||
nonce := DiffUint64{Value: &val.Nonce}
|
nonce := DiffUint64{Value: &val.Nonce}
|
||||||
balance := DiffBigInt{Value: val.Balance}
|
balance := DiffBigInt{Value: val.Balance}
|
||||||
contractRoot := DiffString{Value: &hexRoot}
|
contractRoot := DiffString{Value: &hexRoot}
|
||||||
accountDiffs[addr] = AccountDiffEventual{
|
accountDiffs[addr] = AccountDiff{
|
||||||
Nonce: nonce,
|
Nonce: nonce,
|
||||||
Balance: balance,
|
Balance: balance,
|
||||||
CodeHash: codeHash,
|
CodeHash: codeHash,
|
||||||
@ -172,8 +172,8 @@ func (sdb *builder) buildDiffEventual(accounts map[common.Address]*state.Account
|
|||||||
return accountDiffs, nil
|
return accountDiffs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sdb *builder) buildDiffIncremental(creations map[common.Address]*state.Account, deletions map[common.Address]*state.Account, updatedKeys []string) (map[common.Address]AccountDiffIncremental, error) {
|
func (sdb *builder) buildDiffIncremental(creations map[common.Address]*state.Account, deletions map[common.Address]*state.Account, updatedKeys []string) (map[common.Address]AccountDiff, error) {
|
||||||
updatedAccounts := make(map[common.Address]AccountDiffIncremental)
|
updatedAccounts := make(map[common.Address]AccountDiff)
|
||||||
for _, val := range updatedKeys {
|
for _, val := range updatedKeys {
|
||||||
createdAcc := creations[common.HexToAddress(val)]
|
createdAcc := creations[common.HexToAddress(val)]
|
||||||
deletedAcc := deletions[common.HexToAddress(val)]
|
deletedAcc := deletions[common.HexToAddress(val)]
|
||||||
@ -190,7 +190,7 @@ func (sdb *builder) buildDiffIncremental(creations map[common.Address]*state.Acc
|
|||||||
nHexRoot := createdAcc.Root.Hex()
|
nHexRoot := createdAcc.Root.Hex()
|
||||||
contractRoot := DiffString{Value: &nHexRoot}
|
contractRoot := DiffString{Value: &nHexRoot}
|
||||||
|
|
||||||
updatedAccounts[common.HexToAddress(val)] = AccountDiffIncremental{
|
updatedAccounts[common.HexToAddress(val)] = AccountDiff{
|
||||||
Nonce: nonce,
|
Nonce: nonce,
|
||||||
Balance: balance,
|
Balance: balance,
|
||||||
CodeHash: codeHash,
|
CodeHash: codeHash,
|
||||||
|
@ -31,8 +31,8 @@ var (
|
|||||||
contractCode = common.Hex2Bytes("606060405260cc8060106000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806360cd2685146041578063c16431b914606b57603f565b005b6055600480803590602001909190505060a9565b6040518082815260200191505060405180910390f35b60886004808035906020019091908035906020019091905050608a565b005b80600060005083606481101560025790900160005b50819055505b5050565b6000600060005082606481101560025790900160005b5054905060c7565b91905056")
|
contractCode = common.Hex2Bytes("606060405260cc8060106000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806360cd2685146041578063c16431b914606b57603f565b005b6055600480803590602001909190505060a9565b6040518082815260200191505060405180910390f35b60886004808035906020019091908035906020019091905050608a565b005b80600060005083606481101560025790900160005b50819055505b5050565b6000600060005082606481101560025790900160005b5054905060c7565b91905056")
|
||||||
contractAddr common.Address
|
contractAddr common.Address
|
||||||
|
|
||||||
emptyAccountDiffEventualMap = make(map[common.Address]b.AccountDiffEventual)
|
emptyAccountDiffEventualMap = make(map[common.Address]b.AccountDiff)
|
||||||
emptyAccountDiffIncrementalMap = make(map[common.Address]b.AccountDiffIncremental)
|
emptyAccountDiffIncrementalMap = make(map[common.Address]b.AccountDiff)
|
||||||
|
|
||||||
block0Hash, block1Hash, block2Hash, block3Hash common.Hash
|
block0Hash, block1Hash, block2Hash, block3Hash common.Hash
|
||||||
block0, block1, block2, block3 *types.Block
|
block0, block1, block2, block3 *types.Block
|
||||||
@ -109,7 +109,7 @@ func TestBuilder(t *testing.T) {
|
|||||||
&b.StateDiff{
|
&b.StateDiff{
|
||||||
BlockNumber: block1.Number().Int64(),
|
BlockNumber: block1.Number().Int64(),
|
||||||
BlockHash: block1.Hash(),
|
BlockHash: block1.Hash(),
|
||||||
CreatedAccounts: map[common.Address]b.AccountDiffEventual{
|
CreatedAccounts: map[common.Address]b.AccountDiff{
|
||||||
account1Addr: {
|
account1Addr: {
|
||||||
Nonce: b.DiffUint64{Value: &nonce0},
|
Nonce: b.DiffUint64{Value: &nonce0},
|
||||||
Balance: b.DiffBigInt{Value: big.NewInt(balanceChange10000)},
|
Balance: b.DiffBigInt{Value: big.NewInt(balanceChange10000)},
|
||||||
@ -126,7 +126,7 @@ func TestBuilder(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
DeletedAccounts: emptyAccountDiffEventualMap,
|
DeletedAccounts: emptyAccountDiffEventualMap,
|
||||||
UpdatedAccounts: map[common.Address]b.AccountDiffIncremental{
|
UpdatedAccounts: map[common.Address]b.AccountDiff{
|
||||||
testBankAddress: {
|
testBankAddress: {
|
||||||
Nonce: b.DiffUint64{Value: &nonce1},
|
Nonce: b.DiffUint64{Value: &nonce1},
|
||||||
Balance: b.DiffBigInt{Value: big.NewInt(testBankFunds.Int64() - balanceChange10000)},
|
Balance: b.DiffBigInt{Value: big.NewInt(testBankFunds.Int64() - balanceChange10000)},
|
||||||
@ -150,7 +150,7 @@ func TestBuilder(t *testing.T) {
|
|||||||
&b.StateDiff{
|
&b.StateDiff{
|
||||||
BlockNumber: block2.Number().Int64(),
|
BlockNumber: block2.Number().Int64(),
|
||||||
BlockHash: block2.Hash(),
|
BlockHash: block2.Hash(),
|
||||||
CreatedAccounts: map[common.Address]b.AccountDiffEventual{
|
CreatedAccounts: map[common.Address]b.AccountDiff{
|
||||||
account2Addr: {
|
account2Addr: {
|
||||||
Nonce: b.DiffUint64{Value: &nonce0},
|
Nonce: b.DiffUint64{Value: &nonce0},
|
||||||
Balance: b.DiffBigInt{Value: big.NewInt(balanceChange1000)},
|
Balance: b.DiffBigInt{Value: big.NewInt(balanceChange1000)},
|
||||||
@ -167,7 +167,7 @@ func TestBuilder(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
DeletedAccounts: emptyAccountDiffEventualMap,
|
DeletedAccounts: emptyAccountDiffEventualMap,
|
||||||
UpdatedAccounts: map[common.Address]b.AccountDiffIncremental{
|
UpdatedAccounts: map[common.Address]b.AccountDiff{
|
||||||
testBankAddress: {
|
testBankAddress: {
|
||||||
Nonce: b.DiffUint64{Value: &nonce2},
|
Nonce: b.DiffUint64{Value: &nonce2},
|
||||||
Balance: b.DiffBigInt{Value: big.NewInt(block1BankBalance - balanceChange1000)},
|
Balance: b.DiffBigInt{Value: big.NewInt(block1BankBalance - balanceChange1000)},
|
||||||
@ -205,9 +205,9 @@ func TestBuilder(t *testing.T) {
|
|||||||
&b.StateDiff{
|
&b.StateDiff{
|
||||||
BlockNumber: block3.Number().Int64(),
|
BlockNumber: block3.Number().Int64(),
|
||||||
BlockHash: block3.Hash(),
|
BlockHash: block3.Hash(),
|
||||||
CreatedAccounts: map[common.Address]b.AccountDiffEventual{},
|
CreatedAccounts: map[common.Address]b.AccountDiff{},
|
||||||
DeletedAccounts: emptyAccountDiffEventualMap,
|
DeletedAccounts: emptyAccountDiffEventualMap,
|
||||||
UpdatedAccounts: map[common.Address]b.AccountDiffIncremental{
|
UpdatedAccounts: map[common.Address]b.AccountDiff{
|
||||||
account2Addr: {
|
account2Addr: {
|
||||||
Nonce: b.DiffUint64{Value: &nonce0},
|
Nonce: b.DiffUint64{Value: &nonce0},
|
||||||
Balance: b.DiffBigInt{Value: big.NewInt(block2Account2Balance + miningReward)},
|
Balance: b.DiffBigInt{Value: big.NewInt(block2Account2Balance + miningReward)},
|
||||||
|
@ -27,11 +27,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type StateDiff struct {
|
type StateDiff struct {
|
||||||
BlockNumber int64 `json:"blockNumber" gencodec:"required"`
|
BlockNumber int64 `json:"blockNumber" gencodec:"required"`
|
||||||
BlockHash common.Hash `json:"blockHash" gencodec:"required"`
|
BlockHash common.Hash `json:"blockHash" gencodec:"required"`
|
||||||
CreatedAccounts map[common.Address]AccountDiffEventual `json:"createdAccounts" gencodec:"required"`
|
CreatedAccounts map[common.Address]AccountDiff `json:"createdAccounts" gencodec:"required"`
|
||||||
DeletedAccounts map[common.Address]AccountDiffEventual `json:"deletedAccounts" gencodec:"required"`
|
DeletedAccounts map[common.Address]AccountDiff `json:"deletedAccounts" gencodec:"required"`
|
||||||
UpdatedAccounts map[common.Address]AccountDiffIncremental `json:"updatedAccounts" gencodec:"required"`
|
UpdatedAccounts map[common.Address]AccountDiff `json:"updatedAccounts" gencodec:"required"`
|
||||||
|
|
||||||
encoded []byte
|
encoded []byte
|
||||||
err error
|
err error
|
||||||
@ -55,15 +55,7 @@ func (sd *StateDiff) Encode() ([]byte, error) {
|
|||||||
return sd.encoded, sd.err
|
return sd.encoded, sd.err
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountDiffEventual struct {
|
type AccountDiff struct {
|
||||||
Nonce DiffUint64 `json:"nonce" gencodec:"required"`
|
|
||||||
Balance DiffBigInt `json:"balance" gencodec:"required"`
|
|
||||||
CodeHash string `json:"codeHash" gencodec:"required"`
|
|
||||||
ContractRoot DiffString `json:"contractRoot" gencodec:"required"`
|
|
||||||
Storage map[string]DiffString `json:"storage" gencodec:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AccountDiffIncremental struct {
|
|
||||||
Nonce DiffUint64 `json:"nonce" gencodec:"required"`
|
Nonce DiffUint64 `json:"nonce" gencodec:"required"`
|
||||||
Balance DiffBigInt `json:"balance" gencodec:"required"`
|
Balance DiffBigInt `json:"balance" gencodec:"required"`
|
||||||
CodeHash string `json:"codeHash" gencodec:"required"`
|
CodeHash string `json:"codeHash" gencodec:"required"`
|
||||||
|
@ -97,7 +97,7 @@ func accumulateCreatedAccountRows(sd builder.StateDiff) [][]string {
|
|||||||
return createdAccountRows
|
return createdAccountRows
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatAccountDiffEventual(accountDiff builder.AccountDiffEventual, sd builder.StateDiff, accountAction string) []string {
|
func formatAccountDiffEventual(accountDiff builder.AccountDiff, sd builder.StateDiff, accountAction string) []string {
|
||||||
newContractRoot := accountDiff.ContractRoot.Value
|
newContractRoot := accountDiff.ContractRoot.Value
|
||||||
var storageDiffPaths []string
|
var storageDiffPaths []string
|
||||||
for k := range accountDiff.Storage {
|
for k := range accountDiff.Storage {
|
||||||
@ -116,7 +116,7 @@ func formatAccountDiffEventual(accountDiff builder.AccountDiffEventual, sd build
|
|||||||
return formattedAccountData
|
return formattedAccountData
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatAccountDiffIncremental(accountDiff builder.AccountDiffIncremental, sd builder.StateDiff, accountAction string) []string {
|
func formatAccountDiffIncremental(accountDiff builder.AccountDiff, sd builder.StateDiff, accountAction string) []string {
|
||||||
newContractRoot := accountDiff.ContractRoot.Value
|
newContractRoot := accountDiff.ContractRoot.Value
|
||||||
var storageDiffPaths []string
|
var storageDiffPaths []string
|
||||||
for k := range accountDiff.Storage {
|
for k := range accountDiff.Storage {
|
||||||
|
@ -21,7 +21,7 @@ var (
|
|||||||
newStorage = "0x03"
|
newStorage = "0x03"
|
||||||
storage = map[string]builder.DiffString{StoragePath: {Value: &newStorage}}
|
storage = map[string]builder.DiffString{StoragePath: {Value: &newStorage}}
|
||||||
address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592")
|
address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592")
|
||||||
CreatedAccountDiffs = map[common.Address]builder.AccountDiffEventual{address: {
|
CreatedAccountDiffs = map[common.Address]builder.AccountDiff{address: {
|
||||||
Nonce: builder.DiffUint64{Value: &NewNonceValue},
|
Nonce: builder.DiffUint64{Value: &NewNonceValue},
|
||||||
Balance: builder.DiffBigInt{Value: big.NewInt(NewBalanceValue)},
|
Balance: builder.DiffBigInt{Value: big.NewInt(NewBalanceValue)},
|
||||||
ContractRoot: builder.DiffString{Value: &ContractRoot},
|
ContractRoot: builder.DiffString{Value: &ContractRoot},
|
||||||
@ -29,7 +29,7 @@ var (
|
|||||||
Storage: storage,
|
Storage: storage,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
UpdatedAccountDiffs = map[common.Address]builder.AccountDiffIncremental{address: {
|
UpdatedAccountDiffs = map[common.Address]builder.AccountDiff{address: {
|
||||||
Nonce: builder.DiffUint64{Value: &NewNonceValue},
|
Nonce: builder.DiffUint64{Value: &NewNonceValue},
|
||||||
Balance: builder.DiffBigInt{Value: big.NewInt(NewBalanceValue)},
|
Balance: builder.DiffBigInt{Value: big.NewInt(NewBalanceValue)},
|
||||||
CodeHash: CodeHash,
|
CodeHash: CodeHash,
|
||||||
@ -37,7 +37,7 @@ var (
|
|||||||
Storage: storage,
|
Storage: storage,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
DeletedAccountDiffs = map[common.Address]builder.AccountDiffEventual{address: {
|
DeletedAccountDiffs = map[common.Address]builder.AccountDiff{address: {
|
||||||
Nonce: builder.DiffUint64{Value: &NewNonceValue},
|
Nonce: builder.DiffUint64{Value: &NewNonceValue},
|
||||||
Balance: builder.DiffBigInt{Value: big.NewInt(NewBalanceValue)},
|
Balance: builder.DiffBigInt{Value: big.NewInt(NewBalanceValue)},
|
||||||
ContractRoot: builder.DiffString{Value: &ContractRoot},
|
ContractRoot: builder.DiffString{Value: &ContractRoot},
|
||||||
|
Loading…
Reference in New Issue
Block a user