erigon-pulse/turbo/shards/state_change_accumulator.go

160 lines
5.9 KiB
Go
Raw Normal View History

State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
package shards
import (
2021-08-17 08:52:55 +00:00
"context"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/gointerfaces"
"github.com/ledgerwatch/erigon-lib/gointerfaces/remote"
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
"github.com/ledgerwatch/erigon/common"
2021-09-26 16:09:36 +00:00
"github.com/ledgerwatch/erigon/params"
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
)
// Accumulator collects state changes in a form that can then be delivered to the RPC daemon
type Accumulator struct {
2021-09-17 03:31:20 +00:00
viewID uint64 // mdbx's txID
2021-09-26 16:09:36 +00:00
chainConfig *params.ChainConfig
2021-09-17 03:31:20 +00:00
changes []*remote.StateChange
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
latestChange *remote.StateChange
accountChangeIndex map[common.Address]int // For the latest changes, allows finding account change by account's address
storageChangeIndex map[common.Address]map[common.Hash]int
}
2021-09-26 16:09:36 +00:00
func NewAccumulator(chainConfig *params.ChainConfig) *Accumulator {
return &Accumulator{chainConfig: chainConfig}
}
2021-08-17 08:52:55 +00:00
type StateChangeConsumer interface {
2021-09-17 03:31:20 +00:00
SendStateChanges(ctx context.Context, sc *remote.StateChangeBatch)
2021-08-17 08:52:55 +00:00
}
2021-09-17 03:31:20 +00:00
func (a *Accumulator) Reset(viewID uint64) {
a.changes = nil
a.latestChange = nil
a.accountChangeIndex = nil
a.storageChangeIndex = nil
2021-09-17 03:31:20 +00:00
a.viewID = viewID
}
2021-09-26 16:09:36 +00:00
func (a *Accumulator) ChainConfig() *params.ChainConfig { return a.chainConfig }
func (a *Accumulator) SendAndReset(ctx context.Context, c StateChangeConsumer, pendingBaseFee uint64, blockGasLimit uint64) {
2021-08-17 08:52:55 +00:00
if a == nil || c == nil || len(a.changes) == 0 {
return
}
sc := &remote.StateChangeBatch{DatabaseViewID: a.viewID, ChangeBatch: a.changes, PendingBlockBaseFee: pendingBaseFee, BlockGasLimit: blockGasLimit}
2021-09-26 16:09:36 +00:00
c.SendStateChanges(ctx, sc)
2021-09-17 03:31:20 +00:00
a.Reset(0) // reset here for GC, but there will be another Reset with correct viewID
2021-08-17 08:52:55 +00:00
}
2021-08-17 08:52:55 +00:00
// StartChange begins accumulation of changes for a new block
2021-09-26 16:09:36 +00:00
func (a *Accumulator) StartChange(blockHeight uint64, blockHash common.Hash, txs [][]byte, unwind bool) {
2021-09-17 03:31:20 +00:00
a.changes = append(a.changes, &remote.StateChange{})
a.latestChange = a.changes[len(a.changes)-1]
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
a.latestChange.BlockHeight = blockHeight
a.latestChange.BlockHash = gointerfaces.ConvertHashToH256(blockHash)
if unwind {
a.latestChange.Direction = remote.Direction_UNWIND
} else {
a.latestChange.Direction = remote.Direction_FORWARD
}
a.accountChangeIndex = make(map[common.Address]int)
a.storageChangeIndex = make(map[common.Address]map[common.Hash]int)
2021-08-17 08:52:55 +00:00
if txs != nil {
a.latestChange.Txs = make([][]byte, len(txs))
for i := range txs {
a.latestChange.Txs[i] = libcommon.Copy(txs[i])
2021-08-17 08:52:55 +00:00
}
}
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
}
2021-08-17 08:52:55 +00:00
// ChangeAccount adds modification of account balance or nonce (or both) to the latest change
func (a *Accumulator) ChangeAccount(address common.Address, incarnation uint64, data []byte) {
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
i, ok := a.accountChangeIndex[address]
if !ok || incarnation > a.latestChange.Changes[i].Incarnation {
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
// Account has not been changed in the latest block yet
i = len(a.latestChange.Changes)
2021-08-17 08:52:55 +00:00
a.latestChange.Changes = append(a.latestChange.Changes, &remote.AccountChange{Address: gointerfaces.ConvertAddressToH160(address)})
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
a.accountChangeIndex[address] = i
}
accountChange := a.latestChange.Changes[i]
switch accountChange.Action {
case remote.Action_STORAGE:
accountChange.Action = remote.Action_UPSERT
case remote.Action_CODE:
accountChange.Action = remote.Action_UPSERT_CODE
case remote.Action_REMOVE:
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
panic("")
}
accountChange.Incarnation = incarnation
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
accountChange.Data = data
}
// DeleteAccount marks account as deleted
func (a *Accumulator) DeleteAccount(address common.Address) {
i, ok := a.accountChangeIndex[address]
if !ok {
// Account has not been changed in the latest block yet
i = len(a.latestChange.Changes)
2021-08-17 08:52:55 +00:00
a.latestChange.Changes = append(a.latestChange.Changes, &remote.AccountChange{Address: gointerfaces.ConvertAddressToH160(address)})
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
a.accountChangeIndex[address] = i
}
accountChange := a.latestChange.Changes[i]
if accountChange.Action != remote.Action_STORAGE {
panic("")
}
accountChange.Data = nil
accountChange.Code = nil
accountChange.StorageChanges = nil
accountChange.Action = remote.Action_REMOVE
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
}
// ChangeCode adds code to the latest change
func (a *Accumulator) ChangeCode(address common.Address, incarnation uint64, code []byte) {
i, ok := a.accountChangeIndex[address]
if !ok || incarnation > a.latestChange.Changes[i].Incarnation {
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
// Account has not been changed in the latest block yet
i = len(a.latestChange.Changes)
a.latestChange.Changes = append(a.latestChange.Changes, &remote.AccountChange{Address: gointerfaces.ConvertAddressToH160(address), Action: remote.Action_CODE})
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
a.accountChangeIndex[address] = i
}
accountChange := a.latestChange.Changes[i]
switch accountChange.Action {
case remote.Action_STORAGE:
accountChange.Action = remote.Action_CODE
case remote.Action_UPSERT:
accountChange.Action = remote.Action_UPSERT_CODE
case remote.Action_REMOVE:
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
panic("")
}
accountChange.Incarnation = incarnation
accountChange.Code = code
}
func (a *Accumulator) ChangeStorage(address common.Address, incarnation uint64, location common.Hash, data []byte) {
i, ok := a.accountChangeIndex[address]
if !ok || incarnation > a.latestChange.Changes[i].Incarnation {
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
// Account has not been changed in the latest block yet
i = len(a.latestChange.Changes)
a.latestChange.Changes = append(a.latestChange.Changes, &remote.AccountChange{Address: gointerfaces.ConvertAddressToH160(address), Action: remote.Action_STORAGE})
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
a.accountChangeIndex[address] = i
}
accountChange := a.latestChange.Changes[i]
if accountChange.Action == remote.Action_REMOVE {
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
panic("")
}
accountChange.Incarnation = incarnation
si, ok1 := a.storageChangeIndex[address]
if !ok1 {
si = make(map[common.Hash]int)
a.storageChangeIndex[address] = si
}
j, ok2 := si[location]
if !ok2 {
j = len(accountChange.StorageChanges)
accountChange.StorageChanges = append(accountChange.StorageChanges, &remote.StorageChange{})
si[location] = j
}
storageChange := accountChange.StorageChanges[j]
storageChange.Location = gointerfaces.ConvertHashToH256(location)
storageChange.Data = data
}