mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-06 19:06:42 +01:00
Synchronize the AccountCreationAuths from L1CoordinatorTxs
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum"
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
"github.com/hermeznetwork/hermez-node/db/historydb"
|
||||
"github.com/hermeznetwork/hermez-node/db/l2db"
|
||||
"github.com/hermeznetwork/hermez-node/db/statedb"
|
||||
"github.com/hermeznetwork/hermez-node/eth"
|
||||
"github.com/hermeznetwork/hermez-node/log"
|
||||
@@ -215,6 +216,7 @@ type Synchronizer struct {
|
||||
ethClient eth.ClientInterface
|
||||
consts SCConsts
|
||||
historyDB *historydb.HistoryDB
|
||||
l2DB *l2db.L2DB
|
||||
stateDB *statedb.StateDB
|
||||
cfg Config
|
||||
initVars SCVariables
|
||||
@@ -226,7 +228,7 @@ type Synchronizer struct {
|
||||
|
||||
// NewSynchronizer creates a new Synchronizer
|
||||
func NewSynchronizer(ethClient eth.ClientInterface, historyDB *historydb.HistoryDB,
|
||||
stateDB *statedb.StateDB, cfg Config) (*Synchronizer, error) {
|
||||
l2DB *l2db.L2DB, stateDB *statedb.StateDB, cfg Config) (*Synchronizer, error) {
|
||||
auctionConstants, err := ethClient.AuctionConstants()
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("NewSynchronizer ethClient.AuctionConstants(): %w",
|
||||
@@ -271,6 +273,7 @@ func NewSynchronizer(ethClient eth.ClientInterface, historyDB *historydb.History
|
||||
ethClient: ethClient,
|
||||
consts: consts,
|
||||
historyDB: historyDB,
|
||||
l2DB: l2DB,
|
||||
stateDB: stateDB,
|
||||
cfg: cfg,
|
||||
initVars: *initVars,
|
||||
@@ -657,7 +660,7 @@ func (s *Synchronizer) Sync(ctx context.Context,
|
||||
if len(rollupData.Batches) > 0 {
|
||||
hasBatch = true
|
||||
}
|
||||
if err := s.updateCurrentNextSlotIfSync(false, hasBatch); err != nil {
|
||||
if err = s.updateCurrentNextSlotIfSync(false, hasBatch); err != nil {
|
||||
return nil, nil, tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
@@ -895,6 +898,9 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e
|
||||
|
||||
position = len(l1UserTxs)
|
||||
}
|
||||
|
||||
l1TxsAuth := make([]common.AccountCreationAuth,
|
||||
0, len(forgeBatchArgs.L1CoordinatorTxsAuths))
|
||||
// Get L1 Coordinator Txs
|
||||
for i := range forgeBatchArgs.L1CoordinatorTxs {
|
||||
l1CoordinatorTx := forgeBatchArgs.L1CoordinatorTxs[i]
|
||||
@@ -910,9 +916,30 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e
|
||||
|
||||
batchData.L1CoordinatorTxs = append(batchData.L1CoordinatorTxs, *l1Tx)
|
||||
position++
|
||||
|
||||
// Create a slice of account creation auth to be
|
||||
// inserted later if not exists
|
||||
if l1CoordinatorTx.FromEthAddr != common.RollupConstEthAddressInternalOnly {
|
||||
l1CoordinatorTxAuth := forgeBatchArgs.L1CoordinatorTxsAuths[i]
|
||||
l1TxsAuth = append(l1TxsAuth, common.AccountCreationAuth{
|
||||
EthAddr: l1CoordinatorTx.FromEthAddr,
|
||||
BJJ: l1CoordinatorTx.FromBJJ,
|
||||
Signature: l1CoordinatorTxAuth,
|
||||
})
|
||||
}
|
||||
|
||||
// fmt.Println("DGB l1coordtx")
|
||||
}
|
||||
|
||||
// Insert the slice of account creation auth
|
||||
// only if the node run as a coordinator
|
||||
if s.l2DB != nil && len(l1TxsAuth) > 0 {
|
||||
err = s.l2DB.AddManyAccountCreationAuth(l1TxsAuth)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Insert all the txs forged in this batch (l1UserTxs,
|
||||
// L1CoordinatorTxs, PoolL2Txs) into stateDB so that they are
|
||||
// processed.
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
dbUtils "github.com/hermeznetwork/hermez-node/db"
|
||||
"github.com/hermeznetwork/hermez-node/db/historydb"
|
||||
"github.com/hermeznetwork/hermez-node/db/l2db"
|
||||
"github.com/hermeznetwork/hermez-node/db/statedb"
|
||||
"github.com/hermeznetwork/hermez-node/eth"
|
||||
"github.com/hermeznetwork/hermez-node/test"
|
||||
@@ -303,7 +304,7 @@ func TestMain(m *testing.M) {
|
||||
os.Exit(exitVal)
|
||||
}
|
||||
|
||||
func newTestModules(t *testing.T) (*statedb.StateDB, *historydb.HistoryDB) {
|
||||
func newTestModules(t *testing.T) (*statedb.StateDB, *historydb.HistoryDB, *l2db.L2DB) {
|
||||
// Int State DB
|
||||
dir, err := ioutil.TempDir("", "tmpdb")
|
||||
require.NoError(t, err)
|
||||
@@ -321,7 +322,10 @@ func newTestModules(t *testing.T) (*statedb.StateDB, *historydb.HistoryDB) {
|
||||
// Clear DB
|
||||
test.WipeDB(historyDB.DB())
|
||||
|
||||
return stateDB, historyDB
|
||||
// Init L2 DB
|
||||
l2DB := l2db.NewL2DB(db, db, 10, 100, 0.0, 24*time.Hour, nil)
|
||||
|
||||
return stateDB, historyDB, l2DB
|
||||
}
|
||||
|
||||
func newBigInt(s string) *big.Int {
|
||||
@@ -337,7 +341,7 @@ func TestSyncGeneral(t *testing.T) {
|
||||
// Setup
|
||||
//
|
||||
|
||||
stateDB, historyDB := newTestModules(t)
|
||||
stateDB, historyDB, l2DB := newTestModules(t)
|
||||
|
||||
// Init eth client
|
||||
var timer timer
|
||||
@@ -347,7 +351,7 @@ func TestSyncGeneral(t *testing.T) {
|
||||
client := test.NewClient(true, &timer, ðCommon.Address{}, clientSetup)
|
||||
|
||||
// Create Synchronizer
|
||||
s, err := NewSynchronizer(client, historyDB, stateDB, Config{
|
||||
s, err := NewSynchronizer(client, historyDB, l2DB, stateDB, Config{
|
||||
StatsRefreshPeriod: 0 * time.Second,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -727,7 +731,7 @@ func TestSyncGeneral(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSyncForgerCommitment(t *testing.T) {
|
||||
stateDB, historyDB := newTestModules(t)
|
||||
stateDB, historyDB, l2DB := newTestModules(t)
|
||||
|
||||
// Init eth client
|
||||
var timer timer
|
||||
@@ -740,7 +744,7 @@ func TestSyncForgerCommitment(t *testing.T) {
|
||||
client := test.NewClient(true, &timer, ðCommon.Address{}, clientSetup)
|
||||
|
||||
// Create Synchronizer
|
||||
s, err := NewSynchronizer(client, historyDB, stateDB, Config{
|
||||
s, err := NewSynchronizer(client, historyDB, l2DB, stateDB, Config{
|
||||
StatsRefreshPeriod: 0 * time.Second,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -840,7 +844,7 @@ func TestSyncForgerCommitment(t *testing.T) {
|
||||
require.True(t, stats.Synced())
|
||||
syncCommitment[syncBlock.Block.Num] = stats.Sync.Auction.CurrentSlot.ForgerCommitment
|
||||
|
||||
s2, err := NewSynchronizer(client, historyDB, stateDB, Config{
|
||||
s2, err := NewSynchronizer(client, historyDB, l2DB, stateDB, Config{
|
||||
StatsRefreshPeriod: 0 * time.Second,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user