Skip to content

Commit

Permalink
wip: #4
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Nedkov <[email protected]>
  • Loading branch information
Psykepro committed Jan 9, 2023
1 parent 6d2d345 commit 27bf5c2
Show file tree
Hide file tree
Showing 38 changed files with 1,743 additions and 186 deletions.
2 changes: 1 addition & 1 deletion aggregator/mocks/mock_etherman.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion aggregator/mocks/mock_ethtxmanager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion aggregator/mocks/mock_profitabilitychecker.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion aggregator/mocks/mock_prover.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion aggregator/mocks/mock_state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ MaxSteps = 8388608
MaxAllowedFailedCounter = 50
[Sequencer.ProfitabilityChecker]
SendBatchesEvenWhenNotProfitable = true
[Sequencer.Finalizer]
NextGERDeadlineTimeoutInSec = 60
NextForcedBatchDeadlineTimeoutInSec = 60
SleepDurationInMs = 100
ResourcePercentageToCloseBatch = 90
[PriceGetter]
Type = "default"
Expand Down
5 changes: 5 additions & 0 deletions config/environments/local/local.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ MaxSteps = 8388608
MaxAllowedFailedCounter = 50
[Sequencer.ProfitabilityChecker]
SendBatchesEvenWhenNotProfitable = "true"
[Sequencer.Finalizer]
NextGERDeadlineTimeoutInSec = 60
NextForcedBatchDeadlineTimeoutInSec = 60
SleepDurationInMs = 100
ResourcePercentageToCloseBatch = 90

[Aggregator]
Host = "0.0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion etherman/mock_etherscan.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion etherman/mock_ethgasstation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion jsonrpc/mock_dbtx_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion jsonrpc/mock_gasPriceEstimator_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion jsonrpc/mock_pool_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion jsonrpc/mock_state_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion jsonrpc/mock_storage_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sequencer/broadcast/mocks/mock_state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions sequencer/closingsignalsmanager.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package sequencer

import "github.com/ethereum/go-ethereum/common"

// TBD. Considerations:
// - Should wait for a block to be finalized: https://www.alchemy.com/overviews/ethereum-commitment-levels https://ethereum.github.io/beacon-APIs/#/Beacon/getStateFinalityCheckpoints

type closingSignalsManager struct {
finalizer *finalizer
}

type L2ReorgEvent struct {
TxHashes []common.Hash
}

func newClosingSignalsManager(finalizer *finalizer) *closingSignalsManager {
return &closingSignalsManager{finalizer: finalizer}
}
Expand Down
12 changes: 12 additions & 0 deletions sequencer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Config struct {
// WaitPeriodSendSequence is the time the sequencer waits until
// trying to send a sequence to L1
WaitPeriodSendSequence types.Duration `mapstructure:"WaitPeriodSendSequence"`

// WaitPeriodPoolIsEmpty is the time the sequencer waits until
// trying to add new txs to the state
WaitPeriodPoolIsEmpty types.Duration `mapstructure:"WaitPeriodPoolIsEmpty"`
Expand Down Expand Up @@ -77,6 +78,17 @@ type Config struct {

// Maximum allowed failed counter for the tx before it becomes invalid
MaxAllowedFailedCounter uint64 `mapstructure:"MaxAllowedFailedCounter"`

// Finalizer's specific config properties
Finalizer FinalizerCfg `mapstructure:"FinalizerCfg"`
}

// FinalizerCfg contains the finalizer's configuration properties
type FinalizerCfg struct {
NextGERDeadlineTimeoutInSec types.Duration `mapstructure:"NextGERDeadlineTimeoutInSec"`
NextForcedBatchDeadlineTimeoutInSec types.Duration `mapstructure:"NextForcedBatchDeadlineTimeoutInSec"`
SleepDurationInMs types.Duration `mapstructure:"SleepDurationInMs"`
ResourcePercentageToCloseBatch int `mapstructure:"ResourcePercentageToCloseBatch"`
}

// MaxSequenceSize is a wrapper type that parses token amount to big int
Expand Down
25 changes: 17 additions & 8 deletions sequencer/dbmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func (d *dbManager) GetLastBatchNumber(ctx context.Context) (uint64, error) {
return 0, errors.New("")
}

func (d *dbManager) OpenBatch(ctx context.Context, processingContext state.ProcessingContext, dbTx pgx.Tx) error {
//TODO: Use state interface to OpenBatch in the DB
panic("implement me")
}

func (d *dbManager) CreateFirstBatch(ctx context.Context, sequencerAddress common.Address) state.ProcessingContext {
processingCtx := state.ProcessingContext{
BatchNumber: 1,
Expand Down Expand Up @@ -70,12 +75,12 @@ func (d *dbManager) BeginStateTransaction(ctx context.Context) (pgx.Tx, error) {
return tx, nil
}

func (d *dbManager) StoreProcessedTransaction(ctx context.Context, dbTx pgx.Tx, batchNumber uint64, processedTx *state.ProcessTransactionResponse) error {
func (d *dbManager) StoreProcessedTransaction(ctx context.Context, batchNumber uint64, processedTx *state.ProcessTransactionResponse, dbTx pgx.Tx) error {
// TODO: Implement store of transaction and adding it to the batch
return errors.New("")
}

func (d *dbManager) DeleteTxFromPool(ctx context.Context, dbTx pgx.Tx, txHash common.Hash) error {
func (d *dbManager) DeleteTxFromPool(ctx context.Context, txHash common.Hash, dbTx pgx.Tx) error {
// TODO: Delete transaction from Pool DB
return errors.New("")
}
Expand All @@ -86,14 +91,14 @@ func (d *dbManager) StoreProcessedTxAndDeleteFromPool(ctx context.Context, batch
if err != nil {
// TODO: handle
}
err = d.StoreProcessedTransaction(ctx, dbTx, batchNumber, processedTx)
err = d.StoreProcessedTransaction(ctx, batchNumber, processedTx, dbTx)
if err != nil {
err = dbTx.Rollback(ctx)
if err != nil {
// TODO: handle
}
}
err = d.DeleteTxFromPool(ctx, dbTx, processedTx.TxHash)
err = d.DeleteTxFromPool(ctx, processedTx.TxHash, dbTx)
if err != nil {
err = dbTx.Rollback(ctx)
if err != nil {
Expand All @@ -103,11 +108,11 @@ func (d *dbManager) StoreProcessedTxAndDeleteFromPool(ctx context.Context, batch
}
}

func (d *dbManager) GetWIPBatch(ctx context.Context) (wipBatch, error) {
func (d *dbManager) GetWIPBatch(ctx context.Context) (WipBatch, error) {
// TODO: Make this method to return ready WIP batch it has following cases:
// if lastBatch IS OPEN - load data from it but set wipBatch.initialStateRoot to Last Closed Batch
// if lastBatch IS OPEN - load data from it but set WipBatch.initialStateRoot to Last Closed Batch
// if lastBatch IS CLOSED - open new batch in the database and load all data from the closed one without the txs and increase batch number
return wipBatch{}, errors.New("")
return WipBatch{}, errors.New("")
}

func (d *dbManager) GetLastClosedBatch(ctx context.Context) (state.Batch, error) {
Expand All @@ -131,6 +136,10 @@ func (d *dbManager) GetLastNBatches(ctx context.Context, numBatches uint) ([]*st
return []*state.Batch{}, errors.New("")

}
func (d *dbManager) GetLatestGer(ctx context.Context) (state.GlobalExitRoot, time.Time, error) {
// TODO: Get implementation from old sequencer's batchbuilder
return state.GlobalExitRoot{}, time.Now(), nil
}

// ClosingBatchParameters contains the necessary parameters to close a batch
type ClosingBatchParameters struct {
Expand All @@ -141,7 +150,7 @@ type ClosingBatchParameters struct {
Txs []TxTracker
}

func (d *dbManager) CloseBatch(ctx context.Context, params ClosingBatchParameters) {
func (d *dbManager) CloseBatch(ctx context.Context, params ClosingBatchParameters, dbTx pgx.Tx) {
// TODO: Close current open batch
}

Expand Down
Loading

0 comments on commit 27bf5c2

Please sign in to comment.