Add account_update SQL table with balances and nonces

This commit is contained in:
Eduard S
2021-02-19 10:55:52 +01:00
parent d6ec1910da
commit ed4d39fcd1
11 changed files with 251 additions and 17 deletions

View File

@@ -206,8 +206,9 @@ type SCConsts struct {
// Config is the Synchronizer configuration
type Config struct {
StatsRefreshPeriod time.Duration
ChainID uint16
StatsRefreshPeriod time.Duration
StoreAccountUpdates bool
ChainID uint16
}
// Synchronizer implements the Synchronizer type
@@ -993,6 +994,21 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e
}
batchData.CreatedAccounts = processTxsOut.CreatedAccounts
if s.cfg.StoreAccountUpdates {
batchData.UpdatedAccounts = make([]common.AccountUpdate, 0,
len(processTxsOut.UpdatedAccounts))
for _, acc := range processTxsOut.UpdatedAccounts {
batchData.UpdatedAccounts = append(batchData.UpdatedAccounts,
common.AccountUpdate{
EthBlockNum: blockNum,
BatchNum: batchNum,
Idx: acc.Idx,
Nonce: acc.Nonce,
Balance: acc.Balance,
})
}
}
slotNum := int64(0)
if ethBlock.Num >= s.consts.Auction.GenesisBlockNum {
slotNum = (ethBlock.Num - s.consts.Auction.GenesisBlockNum) /

View File

@@ -171,6 +171,8 @@ func checkSyncBlock(t *testing.T, s *Synchronizer, blockNum int, block, syncBloc
*exit = syncBatch.ExitTree[j]
}
assert.Equal(t, batch.Batch, syncBatch.Batch)
// Ignore updated accounts
syncBatch.UpdatedAccounts = nil
assert.Equal(t, batch, syncBatch)
assert.Equal(t, &batch.Batch, dbBatch) //nolint:gosec
@@ -344,7 +346,8 @@ func TestSyncGeneral(t *testing.T) {
// Create Synchronizer
s, err := NewSynchronizer(client, historyDB, stateDB, Config{
StatsRefreshPeriod: 0 * time.Second,
StatsRefreshPeriod: 0 * time.Second,
StoreAccountUpdates: true,
})
require.NoError(t, err)
@@ -735,7 +738,8 @@ func TestSyncForgerCommitment(t *testing.T) {
// Create Synchronizer
s, err := NewSynchronizer(client, historyDB, stateDB, Config{
StatsRefreshPeriod: 0 * time.Second,
StatsRefreshPeriod: 0 * time.Second,
StoreAccountUpdates: true,
})
require.NoError(t, err)
@@ -835,7 +839,8 @@ func TestSyncForgerCommitment(t *testing.T) {
syncCommitment[syncBlock.Block.Num] = stats.Sync.Auction.CurrentSlot.ForgerCommitment
s2, err := NewSynchronizer(client, historyDB, stateDB, Config{
StatsRefreshPeriod: 0 * time.Second,
StatsRefreshPeriod: 0 * time.Second,
StoreAccountUpdates: true,
})
require.NoError(t, err)
stats = s2.Stats()