Parametrize ChainID

This commit is contained in:
arnaucube
2020-12-23 14:53:00 +01:00
parent adc044001f
commit 150597c282
27 changed files with 185 additions and 132 deletions

View File

@@ -31,11 +31,12 @@ type Status struct {
// API serves HTTP requests to allow external interaction with the Hermez node
type API struct {
h *historydb.HistoryDB
cg *configAPI
s *statedb.StateDB
l2 *l2db.L2DB
status Status
h *historydb.HistoryDB
cg *configAPI
s *statedb.StateDB
l2 *l2db.L2DB
status Status
chainID uint16
}
// NewAPI sets the endpoints and the appropriate handlers, but doesn't start the server
@@ -46,6 +47,7 @@ func NewAPI(
sdb *statedb.StateDB,
l2db *l2db.L2DB,
config *Config,
chainID uint16,
) (*API, error) {
// Check input
// TODO: is stateDB only needed for explorer endpoints or for both?
@@ -63,9 +65,10 @@ func NewAPI(
AuctionConstants: config.AuctionConstants,
WDelayerConstants: config.WDelayerConstants,
},
s: sdb,
l2: l2db,
status: Status{},
s: sdb,
l2: l2db,
status: Status{},
chainID: chainID,
}
// Add coordinator endpoints

View File

@@ -211,7 +211,8 @@ func TestMain(m *testing.M) {
panic(err)
}
}()
sdb, err := statedb.NewStateDB(dir, statedb.TypeTxSelector, 0)
chainID := uint16(0)
sdb, err := statedb.NewStateDB(dir, statedb.TypeTxSelector, 0, chainID)
if err != nil {
panic(err)
}
@@ -237,6 +238,7 @@ func TestMain(m *testing.M) {
sdb,
l2DB,
&_config,
chainID,
)
if err != nil {
panic(err)
@@ -253,7 +255,7 @@ func TestMain(m *testing.M) {
test.WipeDB(api.h.DB())
// Genratre blockchain data with til
tcc := til.NewContext(common.RollupConstMaxL1UserTx)
tcc := til.NewContext(chainID, common.RollupConstMaxL1UserTx)
tilCfgExtra := til.ConfigExtra{
BootCoordAddr: ethCommon.HexToAddress("0xE39fEc6224708f0772D2A74fd3f9055A90E0A9f2"),
CoordUser: "Coord",

View File

@@ -180,7 +180,7 @@ func (a *API) verifyPoolL2TxWrite(txw *l2db.PoolL2TxWrite) error {
return tracerr.Wrap(err)
}
// Check signature
if !poolTx.VerifySignature(account.PublicKey) {
if !poolTx.VerifySignature(a.chainID, account.PublicKey) {
return tracerr.Wrap(errors.New("wrong signature"))
}
return nil