Skip to content

Commit

Permalink
Merge pull request #29 from tokamak-network/fix/remove-l2db
Browse files Browse the repository at this point in the history
Fix: remove l2db
  • Loading branch information
Shailu-s authored Dec 24, 2024
2 parents 04b3f6e + f6b26c1 commit 5f7c51f
Show file tree
Hide file tree
Showing 28 changed files with 38 additions and 797 deletions.
1 change: 0 additions & 1 deletion .github/workflows/synchronizer.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
paths:
- "sequencer/synchronizer/**"
- "sequencer/database/historydb/**"
- "sequencer/database/l2db/**"
- "sequencer/database/statedb/**"
- "sequencer/txprocessor/**"
- "sequencer/test/til/**"
Expand Down
7 changes: 0 additions & 7 deletions sequencer/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"tokamak-sybil-resistance/api/coordinatornetwork"
"tokamak-sybil-resistance/common"
"tokamak-sybil-resistance/database/historydb"
"tokamak-sybil-resistance/database/l2db"
"tokamak-sybil-resistance/database/statedb"

ethCommon "github.com/ethereum/go-ethereum/common"
Expand All @@ -20,7 +19,6 @@ import (
type API struct {
historyDB *historydb.HistoryDB
config *configAPI
l2DB *l2db.L2DB
stateDB *statedb.StateDB
hermezAddress ethCommon.Address
validate *validator.Validate
Expand All @@ -39,7 +37,6 @@ type Config struct {
ExplorerEndpoints bool
Server *gin.Engine
HistoryDB *historydb.HistoryDB
L2DB *l2db.L2DB
StateDB *statedb.StateDB
EthClient *ethclient.Client
ForgerAddress *ethCommon.Address
Expand All @@ -49,9 +46,6 @@ type Config struct {
// NewAPI sets the endpoints and the appropriate handlers, but doesn't start the server
func NewAPI(setup Config) (*API, error) {
// Check input
if setup.CoordinatorEndpoints && setup.L2DB == nil {
return nil, common.Wrap(errors.New("cannot serve Coordinator endpoints without L2DB"))
}
if setup.ExplorerEndpoints && setup.HistoryDB == nil {
return nil, common.Wrap(errors.New("cannot serve Explorer endpoints without HistoryDB"))
}
Expand All @@ -66,7 +60,6 @@ func NewAPI(setup Config) (*API, error) {
RollupConstants: *newRollupConstants(consts.Rollup),
ChainID: consts.ChainID,
},
l2DB: setup.L2DB,
stateDB: setup.StateDB,
hermezAddress: consts.HermezAddress,
validate: nil, //TODO: Add validations
Expand Down
2 changes: 0 additions & 2 deletions sequencer/cfg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ SyncRetryInterval = "1s"
#ForgeDelay = "600s"
### Delay after a forged batch if there are no txs to forge. If It is set to 0s, the coordinator will continuously forge even if the batches are empty
#ForgeNoTxsDelay = "86400s"
### Interval between calls to the PurgeByExternalDelete function of the l2db which deletes pending txs externally marked by the column `external_delete`
PurgeByExtDelInterval = "1m"
### Enables the coordinator to forge in slots if the empty slots reach the slot deadline
#MustForgeAtSlotDeadline = true
### It will make the coordinator forge at most one batch per slot, only if there are included txs in that batch, or pending l1UserTxs in the smart contract. Setting this parameter overrides `ForgeDelay`, `ForgeNoTxsDelay`, `MustForgeAtSlotDeadline` and `IgnoreSlotCommitment`.
Expand Down
4 changes: 0 additions & 4 deletions sequencer/common/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ type BatchData struct {
L1Batch bool
// L1UserTxs that were forged in the batch
L1UserTxs []L1Tx
// L1CoordinatorTxs []L1Tx
// L2Txs []L2Tx
CreatedAccounts []Account
UpdatedAccounts []AccountUpdate
ExitTree []ExitInfo
Expand All @@ -78,8 +76,6 @@ func NewBatchData() *BatchData {
return &BatchData{
L1Batch: false,
L1UserTxs: make([]L1Tx, 0),
// L1CoordinatorTxs: make([]L1Tx, 0),
// L2Txs: make([]L2Tx, 0),
CreatedAccounts: make([]Account, 0),
ExitTree: make([]ExitInfo, 0),
Batch: Batch{},
Expand Down
1 change: 0 additions & 1 deletion sequencer/common/pooll2tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ func (tx PoolL2Tx) Tx() Tx {
ToIdx: tx.ToIdx,
Amount: tx.Amount,
Nonce: &tx.Nonce,
Fee: &tx.Fee,
Type: tx.Type,
}
}
Expand Down
3 changes: 0 additions & 3 deletions sequencer/common/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ type Tx struct {
DepositAmount *big.Int `meddler:"deposit_amount,bigintnull"`
DepositAmountFloat *float64 `meddler:"deposit_amount_f"`
DepositAmountUSD *float64 `meddler:"deposit_amount_usd"`
// L2
Fee *FeeSelector `meddler:"fee"`
FeeUSD *float64 `meddler:"fee_usd"`
Nonce *Nonce `meddler:"nonce"`
}

Expand Down
11 changes: 1 addition & 10 deletions sequencer/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,9 @@ type Coordinator struct {
// SyncRetryInterval is the waiting interval between calls to the main
// handler of a synced block after an error
SyncRetryInterval Duration `validate:"required" env:"TONNODE_COORDINATOR_SYNCRETRYINTERVAL"`
// PurgeByExtDelInterval is the waiting interval between calls
// to the PurgeByExternalDelete function of the l2db which deletes
// pending txs externally marked by the column `external_delete`
PurgeByExtDelInterval Duration `validate:"required" env:"TONNODE_COORDINATOR_PURGEBYEXTDELINTERVAL"`
// ProverWaitReadTimeout
ProverWaitReadTimeout Duration `env:"TONNODE_COORDINATOR_PROVERWAITREADTIMEOUT"`
// L2DB is the DB that holds the pool of L2Txs
L2DB struct {
L2DB struct {
// SafetyPeriod is the number of batches after which
// non-pending L2Txs are deleted from the pool
SafetyPeriod common.BatchNum `validate:"required" env:"TONNODE_L2DB_SAFETYPERIOD"`
Expand Down Expand Up @@ -337,10 +332,6 @@ type APIConfigParameters struct {
UpdateMetricsInterval Duration `validate:"required" env:"TONNODE_API_UPDATEMETRICSINTERVAL"`
// UpdateRecommendedFeeInterval is the interval between updates of the recommended fees
UpdateRecommendedFeeInterval Duration `validate:"required" env:"TONNODE_API_UPDATERECOMMENDEDFEEINTERVAL"`
// CoordinatorNetwork enables a pubsub p2p network to share L2 related information among coordinators.
// Only used when running in coordinator mode, as the L2DB is required. Port 3598 will be used and must be open.
// KeyStore must be configured with the Ethereum private key of the coordinator
CoordinatorNetwork bool `env:"TONNODE_API_COORDINATORNETWORK"`
// FindPeersCoordinatorNetworkInterval time elapsed between peer discovery process for the coordinators p2p network
FindPeersCoordinatorNetworkInterval Duration `env:"TONNODE_API_COORDINATORNETWORK_FINDPEERSINTERVAL"`
}
Expand Down
3 changes: 1 addition & 2 deletions sequencer/coordinator/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ type BatchInfo struct {
L1UserTxs []common.L1Tx
// L1CoordTxs []common.L1Tx
L1CoordinatorTxsAuths [][]byte
// L2Txs []common.L2Tx
// CoordIdxs []common.AccountIdx

ForgeBatchArgs *eth.RollupForgeBatchArgs
Auth *bind.TransactOpts `json:"-"`
EthTxs []*types.Transaction
Expand Down
27 changes: 0 additions & 27 deletions sequencer/coordinator/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ type Config struct {
// SyncRetryInterval is the waiting interval between calls to the main
// handler of a synced block after an error
SyncRetryInterval time.Duration
// PurgeByExtDelInterval is the waiting interval between calls
// to the PurgeByExternalDelete function of the l2db which deletes
// pending txs externally marked by the column `external_delete`
PurgeByExtDelInterval time.Duration
// EthClientAttemptsDelay is delay between attempts do do an eth client
// RPC call
EthClientAttemptsDelay time.Duration
Expand All @@ -164,7 +160,6 @@ type Config struct {
// DebugBatchPath if set, specifies the path where batchInfo is stored
// in JSON in every step/update of the pipeline
DebugBatchPath string
Purger PurgerCfg
// VerifierIdx is the index of the verifier contract registered in the
// smart contract
// VerifierIdx uint8
Expand Down Expand Up @@ -218,7 +213,6 @@ type Coordinator struct {
pipeline *Pipeline
lastNonFailedBatchNum common.BatchNum

purger *Purger
txManager *TxManager
}

Expand Down Expand Up @@ -262,13 +256,6 @@ func NewCoordinator(cfg Config,
}
}

purger := Purger{
cfg: cfg.Purger,
lastPurgeBlock: 0,
lastPurgeBatch: 0,
lastInvalidateBlock: 0,
lastInvalidateBatch: 0,
}

ctx, cancel := context.WithCancel(context.Background())
c := Coordinator{
Expand All @@ -291,8 +278,6 @@ func NewCoordinator(cfg Config,
txSelector: txSelector,
batchBuilder: batchBuilder,

purger: &purger,

msgCh: make(chan interface{}, queueLen),
ctx: ctx,
// wg
Expand Down Expand Up @@ -406,7 +391,6 @@ func NewPipeline(
historyDB *historydb.HistoryDB,
txSelector *txselector.TxSelector,
batchBuilder *batchbuilder.BatchBuilder,
purger *Purger,
coord *Coordinator,
txManager *TxManager,
prover prover.Client,
Expand All @@ -425,7 +409,6 @@ func NewPipeline(
txSelector: txSelector,
batchBuilder: batchBuilder,
prover: prover,
purger: purger,
coord: coord,
txManager: txManager,
consts: *scConsts,
Expand All @@ -442,7 +425,6 @@ func (c *Coordinator) newPipeline(ctx context.Context) (*Pipeline, error) {
c.historyDB,
c.txSelector,
c.batchBuilder,
c.purger,
c,
c.txManager,
c.prover,
Expand Down Expand Up @@ -500,15 +482,6 @@ func (c *Coordinator) syncStats(ctx context.Context, stats *synchronizer.Stats)
return common.Wrap(err)
}

// TODO: Purging seems to be relevant to only L2 txs, need to confirm
// if _, err := c.purger.InvalidateMaybe(c.l2DB, c.txSelector.LocalAccountsDB(),
// stats.Sync.LastBlock.Num, int64(stats.Sync.LastBatch.BatchNum)); err != nil {
// return common.Wrap(err)
// }
// if _, err := c.purger.PurgeMaybe(c.l2DB, stats.Sync.LastBlock.Num,
// int64(stats.Sync.LastBatch.BatchNum)); err != nil {
// return common.Wrap(err)
// }
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion sequencer/coordinator/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ type Pipeline struct {
historyDB *historydb.HistoryDB
txSelector *txselector.TxSelector
batchBuilder *batchbuilder.BatchBuilder
purger *Purger

stats synchronizer.Stats
vars common.SCVariables
Expand Down Expand Up @@ -148,6 +147,7 @@ func (p *Pipeline) getErrAtBatchNum() common.BatchNum {
// handleForgeBatch waits for an available proof server, calls p.forgeBatch to
// forge the batch and get the zkInputs, and then sends the zkInputs to the
// selected proof server so that the proof computation begins.

func (p *Pipeline) handleForgeBatch(
ctx context.Context,
batchNum common.BatchNum,
Expand Down
32 changes: 0 additions & 32 deletions sequencer/coordinator/purger.go

This file was deleted.

26 changes: 10 additions & 16 deletions sequencer/coordinator/txmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ type TxManager struct {
cfg Config
ethClient eth.ClientInterface
etherscanService *etherscan.Service
// l2DB *l2db.L2DB // Used only to mark forged txs as forged in the L2DB
coord *Coordinator // Used only to send messages to stop the pipeline
batchCh chan *BatchInfo
chainID *big.Int
account accounts.Account
consts common.SCConsts
coord *Coordinator // Used only to send messages to stop the pipeline
batchCh chan *BatchInfo
chainID *big.Int
account accounts.Account
consts common.SCConsts

stats synchronizer.Stats
vars common.SCVariables
Expand Down Expand Up @@ -77,7 +76,6 @@ func NewTxManager(
ctx context.Context,
cfg *Config,
ethClient eth.ClientInterface,
// l2DB *l2db.L2DB,
coord *Coordinator,
scConsts *common.SCConsts,
initSCVars *common.SCVariables,
Expand All @@ -98,10 +96,9 @@ func NewTxManager(
}
log.Infow("TxManager started", "nonce", accNonce)
return &TxManager{
cfg: *cfg,
ethClient: ethClient,
etherscanService: etherscanService,
// l2DB: l2DB,
cfg: *cfg,
ethClient: ethClient,
etherscanService: etherscanService,
coord: coord,
batchCh: make(chan *BatchInfo, queueLen),
statsVarsCh: make(chan statsVars, queueLen),
Expand Down Expand Up @@ -402,7 +399,8 @@ func (t *TxManager) NewAuth(ctx context.Context, batchInfo *BatchInfo) (*bind.Tr
auth.Value = big.NewInt(0) // in wei

gasLimit := t.cfg.ForgeBatchGasCost.Fixed +
uint64(len(batchInfo.L1UserTxs))*t.cfg.ForgeBatchGasCost.L1UserTx

uint64(len(batchInfo.L1UserTxs))*t.cfg.ForgeBatchGasCost.L1UserTx
// uint64(len(batchInfo.L1UserTxs))*t.cfg.ForgeBatchGasCost.L1UserTx +
// uint64(len(batchInfo.L1CoordTxs))*t.cfg.ForgeBatchGasCost.L1CoordTx +
// uint64(len(batchInfo.L2Txs))*t.cfg.ForgeBatchGasCost.L2Tx
Expand Down Expand Up @@ -512,10 +510,6 @@ func (t *TxManager) sendRollupForgeBatch(ctx context.Context, batchInfo *BatchIn
t.lastSentL1BatchBlockNum = t.stats.Eth.LastBlock.Num + 1
// }
}
// if err := t.l2DB.DoneForging(common.TxIDsFromL2Txs(batchInfo.L2Txs),
// batchInfo.BatchNum); err != nil {
// return tracerr.Wrap(err)
// }
return nil
}

Expand Down
Loading

0 comments on commit 5f7c51f

Please sign in to comment.