mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-06 19:06:42 +01:00
Add account_update SQL table with balances and nonces
This commit is contained in:
@@ -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) /
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user