aggregator

package
v0.5.0-beta5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2024 License: AGPL-3.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstToUpper

func FirstToUpper(s string) string

FirstToUpper returns the string passed as argument with the first letter in uppercase.

Types

type Aggregator

type Aggregator struct {
	prover.UnimplementedAggregatorServiceServer
	// contains filtered or unexported fields
}

Aggregator represents an aggregator

func New

func New(
	ctx context.Context,
	cfg Config,
	logger *log.Logger,
	etherman Etherman) (*Aggregator, error)

New creates a new aggregator.

func (*Aggregator) Channel

Channel implements the bi-directional communication channel between the Prover client and the Aggregator server.

func (*Aggregator) Start

func (a *Aggregator) Start() error

Start starts the aggregator

func (*Aggregator) Stop

func (a *Aggregator) Stop()

Stop stops the Aggregator server.

type Config

type Config struct {
	// Host for the grpc server
	Host string `mapstructure:"Host"`
	// Port for the grpc server
	Port int `mapstructure:"Port"`

	// RetryTime is the time the aggregator main loop sleeps if there are no proofs to aggregate
	// or batches to generate proofs. It is also used in the isSynced loop
	RetryTime types.Duration `mapstructure:"RetryTime"`

	// VerifyProofInterval is the interval of time to verify/send an proof in L1
	VerifyProofInterval types.Duration `mapstructure:"VerifyProofInterval"`

	// ProofStatePollingInterval is the interval time to polling the prover about the generation state of a proof
	ProofStatePollingInterval types.Duration `mapstructure:"ProofStatePollingInterval"`

	// IntervalAfterWhichBatchConsolidateAnyway is the interval duration for the main sequencer to check
	// if there are no transactions. If there are no transactions in this interval, the sequencer will
	// consolidate the batch anyway.
	IntervalAfterWhichBatchConsolidateAnyway types.Duration `mapstructure:"IntervalAfterWhichBatchConsolidateAnyway"`

	// BatchProofSanityCheckEnabled is a flag to enable the sanity check of the batch proof
	BatchProofSanityCheckEnabled bool `mapstructure:"BatchProofSanityCheckEnabled"`

	// ChainID is the L2 ChainID provided by the Network Config
	ChainID uint64

	// ForkID is the L2 ForkID provided by the Network Config
	ForkId uint64 `mapstructure:"ForkId"` //nolint:stylecheck

	// SenderAddress defines which private key the eth tx manager needs to use
	// to sign the L1 txs
	SenderAddress string `mapstructure:"SenderAddress"`

	// CleanupLockedProofsInterval is the interval of time to clean up locked proofs.
	CleanupLockedProofsInterval types.Duration `mapstructure:"CleanupLockedProofsInterval"`

	// GeneratingProofCleanupThreshold represents the time interval after
	// which a proof in generating state is considered to be stuck and
	// allowed to be cleared.
	GeneratingProofCleanupThreshold string `mapstructure:"GeneratingProofCleanupThreshold"`

	// GasOffset is the amount of gas to be added to the gas estimation in order
	// to provide an amount that is higher than the estimated one. This is used
	// to avoid the TX getting reverted in case something has changed in the network
	// state after the estimation which can cause the TX to require more gas to be
	// executed.
	//
	// ex:
	// gas estimation: 1000
	// gas offset: 100
	// final gas: 1100
	GasOffset uint64 `mapstructure:"GasOffset"`

	// RPCURL is the URL of the RPC server
	RPCURL string `mapstructure:"RPCURL"`

	// WitnessURL is the URL of the witness server
	WitnessURL string `mapstructure:"WitnessURL"`

	// UseFullWitness is a flag to enable the use of full witness in the aggregator
	UseFullWitness bool `mapstructure:"UseFullWitness"`

	// DBPath is the path to the database
	DBPath string `mapstructure:"DBPath"`

	// EthTxManager is the config for the ethtxmanager
	EthTxManager ethtxmanager.Config `mapstructure:"EthTxManager"`

	// Log is the log configuration
	Log log.Config `mapstructure:"Log"`

	// Synchornizer config
	Synchronizer syncronizerConfig.Config `mapstructure:"Synchronizer"`

	// SettlementBackend configuration defines how a final ZKP should be settled.
	// It can be settled directly to L1 or over Agglayer.
	SettlementBackend SettlementBackend `mapstructure:"SettlementBackend" jsonschema:"enum=agglayer,enum=l1"`

	// SequencerPrivateKey Private key of the trusted sequencer
	SequencerPrivateKey types.KeystoreFileConfig `mapstructure:"SequencerPrivateKey"`

	// AggLayerTxTimeout is the interval time to wait for a tx to be mined from the agglayer
	AggLayerTxTimeout types.Duration `mapstructure:"AggLayerTxTimeout"`

	// AggLayerURL url of the agglayer service
	AggLayerURL string `mapstructure:"AggLayerURL"`

	// SyncModeOnlyEnabled is a flag that activates sync mode exclusively.
	// When enabled, the aggregator will sync data only from L1 and will not generate or read the data stream.
	SyncModeOnlyEnabled bool `mapstructure:"SyncModeOnlyEnabled"`
}

Config represents the configuration of the aggregator

type EthTxManagerClient added in v0.3.0

type EthTxManagerClient interface {
	Add(
		ctx context.Context,
		to *common.Address,
		value *big.Int,
		data []byte,
		gasOffset uint64,
		sidecar *ethtypes.BlobTxSidecar,
	) (common.Hash, error)
	AddWithGas(
		ctx context.Context,
		to *common.Address,
		value *big.Int,
		data []byte,
		gasOffset uint64,
		sidecar *ethtypes.BlobTxSidecar,
		gas uint64,
	) (common.Hash, error)
	EncodeBlobData(data []byte) (kzg4844.Blob, error)
	MakeBlobSidecar(blobs []kzg4844.Blob) *ethtypes.BlobTxSidecar
	ProcessPendingMonitoredTxs(ctx context.Context, resultHandler ethtxmanager.ResultHandler)
	Remove(ctx context.Context, id common.Hash) error
	RemoveAll(ctx context.Context) error
	Result(ctx context.Context, id common.Hash) (ethtxtypes.MonitoredTxResult, error)
	ResultsByStatus(ctx context.Context, statuses []ethtxtypes.MonitoredTxStatus) ([]ethtxtypes.MonitoredTxResult, error)
	Start()
	Stop()
}

EthTxManagerClient represents the eth tx manager interface

type Etherman added in v0.3.0

type Etherman interface {
	GetRollupId() uint32
	GetLatestVerifiedBatchNum() (uint64, error)
	BuildTrustedVerifyBatchesTxData(
		lastVerifiedBatch, newVerifiedBatch uint64, inputs *ethmanTypes.FinalProofInputs, beneficiary common.Address,
	) (to *common.Address, data []byte, err error)
	GetLatestBlockHeader(ctx context.Context) (*ethtypes.Header, error)
	GetBatchAccInputHash(ctx context.Context, batchNumber uint64) (common.Hash, error)
	HeaderByNumber(ctx context.Context, number *big.Int) (*ethtypes.Header, error)
}

Etherman contains the methods required to interact with ethereum

type ProverInterface added in v0.3.0

type ProverInterface interface {
	Name() string
	ID() string
	Addr() string
	IsIdle() (bool, error)
	BatchProof(input *prover.StatelessInputProver) (*string, error)
	AggregatedProof(inputProof1, inputProof2 string) (*string, error)
	FinalProof(inputProof string, aggregatorAddr string) (*string, error)
	WaitRecursiveProof(ctx context.Context, proofID string) (string, common.Hash, common.Hash, error)
	WaitFinalProof(ctx context.Context, proofID string) (*prover.FinalProof, error)
}

type RPCInterface added in v0.4.0

type RPCInterface interface {
	GetBatch(batchNumber uint64) (*types.RPCBatch, error)
	GetWitness(batchNumber uint64, fullWitness bool) ([]byte, error)
}

Consumer interfaces required by the package.

type SettlementBackend

type SettlementBackend string

SettlementBackend is the type of the settlement backend

const (
	// AggLayer settlement backend
	AggLayer SettlementBackend = "agglayer"

	// L1 settlement backend
	L1 SettlementBackend = "l1"

	// TenToThePowerOf18 represents 1000000000000000000
	TenToThePowerOf18 = 1000000000000000000
)

type StorageInterface

type StorageInterface interface {
	BeginTx(ctx context.Context, options *sql.TxOptions) (db.Txer, error)
	CheckProofContainsCompleteSequences(ctx context.Context, proof *state.Proof, dbTx db.Txer) (bool, error)
	GetProofReadyToVerify(ctx context.Context, lastVerfiedBatchNumber uint64, dbTx db.Txer) (*state.Proof, error)
	GetProofsToAggregate(ctx context.Context, dbTx db.Txer) (*state.Proof, *state.Proof, error)
	AddGeneratedProof(ctx context.Context, proof *state.Proof, dbTx db.Txer) error
	UpdateGeneratedProof(ctx context.Context, proof *state.Proof, dbTx db.Txer) error
	DeleteGeneratedProofs(ctx context.Context, batchNumber uint64, batchNumberFinal uint64, dbTx db.Txer) error
	DeleteUngeneratedProofs(ctx context.Context, dbTx db.Txer) error
	CleanupGeneratedProofs(ctx context.Context, batchNumber uint64, dbTx db.Txer) error
	CleanupLockedProofs(ctx context.Context, duration string, dbTx db.Txer) (int64, error)
	CheckProofExistsForBatch(ctx context.Context, batchNumber uint64, dbTx db.Txer) (bool, error)
	AddSequence(ctx context.Context, sequence state.Sequence, dbTx db.Txer) error
}

StateInterface gathers the methods to interact with the state.

type TokenAmountWithDecimals

type TokenAmountWithDecimals struct {
	*big.Int `validate:"required"`
}

TokenAmountWithDecimals is a wrapper type that parses token amount with decimals to big int

func (*TokenAmountWithDecimals) UnmarshalText

func (t *TokenAmountWithDecimals) UnmarshalText(data []byte) error

UnmarshalText unmarshal token amount from float string to big int

Directories

Path Synopsis
db

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL