state

package
v0.3.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// StreamTypeSequencer represents a Sequencer stream
	StreamTypeSequencer datastreamer.StreamType = 1
	// EntryTypeBookMark represents a bookmark entry
	EntryTypeBookMark datastreamer.EntryType = datastreamer.EtBookmark
)
View Source
const (
	// FORKID_BLUEBERRY is the fork id 4
	FORKID_BLUEBERRY = 4 //nolint:stylecheck
	// FORKID_DRAGONFRUIT is the fork id 5
	FORKID_DRAGONFRUIT = 5 //nolint:stylecheck
	// FORKID_INCABERRY is the fork id 6
	FORKID_INCABERRY = 6 //nolint:stylecheck
	// FORKID_ETROG is the fork id 7
	FORKID_ETROG = 7 //nolint:stylecheck
)
View Source
const (

	// MaxEffectivePercentage is the maximum value that can be used as effective percentage
	MaxEffectivePercentage = uint8(255)

	// EfficiencyPercentageByteLength is the length of the effective percentage in bytes
	EfficiencyPercentageByteLength uint64 = 1
)

Variables

View Source
var (
	// ErrBatchV2DontStartWithChangeL2Block is returned when the batch start directly
	// with a trsansaction (without a preceding changeL2Block)
	ErrBatchV2DontStartWithChangeL2Block = errors.New(
		"batch v2 must start with changeL2Block before Tx (suspect a V1 Batch or a ForcedBatch?)",
	)
	// ErrInvalidBatchV2 is returned when the batch is invalid.
	ErrInvalidBatchV2 = errors.New("invalid batch v2")
	// ErrInvalidRLP is returned when the rlp is invalid.
	ErrInvalidRLP = errors.New("invalid rlp codification")
)
View Source
var (
	// ErrInvalidBatchHeader indicates the batch header is invalid
	ErrInvalidBatchHeader = errors.New("invalid batch header")
	// ErrUnexpectedBatch indicates that the batch is unexpected
	ErrUnexpectedBatch = errors.New("unexpected batch")
	// ErrStateNotSynchronized indicates the state database may be empty
	ErrStateNotSynchronized = errors.New("state not synchronized")
	// ErrNotFound indicates an object has not been found for the search criteria used
	ErrNotFound = errors.New("object not found")
	// ErrNilDBTransaction indicates the db transaction has not been properly initialized
	ErrNilDBTransaction = errors.New("database transaction not properly initialized")
	// ErrAlreadyInitializedDBTransaction indicates the db transaction was already initialized
	ErrAlreadyInitializedDBTransaction = errors.New("database transaction already initialized")
	// ErrNotEnoughIntrinsicGas indicates the gas is not enough to cover the intrinsic gas cost
	ErrNotEnoughIntrinsicGas = fmt.Errorf("not enough gas supplied for intrinsic gas costs")
	// ErrParsingExecutorTrace indicates an error occurred while parsing the executor trace
	ErrParsingExecutorTrace = fmt.Errorf("error while parsing executor trace")
	// ErrInvalidBatchNumber indicates the provided batch number is not the latest in db
	ErrInvalidBatchNumber = errors.New("provided batch number is not latest")
	// ErrLastBatchShouldBeClosed indicates that last batch needs to be closed before adding a new one
	ErrLastBatchShouldBeClosed = errors.New("last batch needs to be closed before adding a new one")
	// ErrBatchAlreadyClosed indicates that batch is already closed
	ErrBatchAlreadyClosed = errors.New("batch is already closed")
	// ErrClosingBatchWithoutTxs indicates that the batch attempted to close does not have txs.
	ErrClosingBatchWithoutTxs = errors.New("can not close a batch without transactions")
	// ErrTimestampGE indicates that timestamp needs to be greater or equal
	ErrTimestampGE = errors.New("timestamp needs to be greater or equal")
	// ErrDBTxNil indicates that the method requires a dbTx that is not nil
	ErrDBTxNil = errors.New("the method requires a dbTx that is not nil")
	// ErrExistingTxGreaterThanProcessedTx indicates that we have more txs stored
	// in db than the txs we want to process.
	ErrExistingTxGreaterThanProcessedTx = errors.New(
		"there are more transactions in the database than in the processed transaction set",
	)
	// ErrOutOfOrderProcessedTx indicates the the processed transactions of an
	// ongoing batch are not in the same order as the transactions stored in the
	// database for the same batch.
	ErrOutOfOrderProcessedTx = errors.New(
		"the processed transactions are not in the same order as the stored transactions",
	)
	// ErrInsufficientFundsForTransfer is returned if the transaction sender doesn't
	// have enough funds for transfer(topmost call only).
	ErrInsufficientFundsForTransfer = errors.New("insufficient funds for transfer")
	// ErrExecutorNil indicates that the method requires an executor that is not nil
	ErrExecutorNil = errors.New("the method requires an executor that is not nil")
	// ErrStateTreeNil indicates that the method requires a state tree that is not nil
	ErrStateTreeNil = errors.New("the method requires a state tree that is not nil")
	// ErrUnsupportedDuration is returned if the provided unit for a time
	// interval is not supported by our conversion mechanism.
	ErrUnsupportedDuration = errors.New("unsupported time duration")
	// ErrInvalidData is the error when the raw txs is unexpected
	ErrInvalidData = errors.New("invalid data")
	// ErrInvalidBlockRange returned when the selected block range is invalid, generally
	// because the toBlock is bigger than the fromBlock
	ErrInvalidBlockRange = errors.New("invalid block range")
	// ErrMaxLogsCountLimitExceeded returned when the number of logs is bigger than the
	// configured limit
	ErrMaxLogsCountLimitExceeded = errors.New("query returned more than %v results")
	// ErrMaxLogsBlockRangeLimitExceeded returned when the range between block number range
	// to filter logs is bigger than the configured limit
	ErrMaxLogsBlockRangeLimitExceeded = errors.New("logs are limited to a %v block range")
	// ErrMaxNativeBlockHashBlockRangeLimitExceeded returned when the range between block number range
	// to filter native block hashes is bigger than the configured limit
	ErrMaxNativeBlockHashBlockRangeLimitExceeded = errors.New("native block hashes are limited to a %v block range")
)
View Source
var (
	// ZeroHash is the hash 0x0000000000000000000000000000000000000000000000000000000000000000
	ZeroHash = common.Hash{}
	// ZeroAddress is the address 0x0000000000000000000000000000000000000000
	ZeroAddress = common.Address{}
)

Functions

func DecodeTx

func DecodeTx(encodedTx string) (*types.Transaction, error)

DecodeTx decodes a string rlp tx representation into a types.Transaction instance

func DecodeTxs

func DecodeTxs(txsData []byte, forkID uint64) ([]*types.Transaction, []byte, []uint8, error)

DecodeTxs extracts Transactions for its encoded form

func EncodeBatchV2

func EncodeBatchV2(batch *BatchRawV2) ([]byte, error)

EncodeBatchV2 encodes a batch of transactions into a byte slice.

func GetSender

func GetSender(tx *types.Transaction) (common.Address, error)

GetSender gets the sender from the transaction's signature

func RlpFieldsToLegacyTx

func RlpFieldsToLegacyTx(fields [][]byte, v, r, s []byte) (tx *types.LegacyTx, err error)

RlpFieldsToLegacyTx parses the rlp fields slice into a type.LegacyTx in this specific order:

required fields: [0] Nonce uint64 [1] GasPrice *big.Int [2] Gas uint64 [3] To *common.Address [4] Value *big.Int [5] Data []byte

optional fields: [6] V *big.Int [7] R *big.Int [8] S *big.Int

Types

type Batch

type Batch struct {
	BatchNumber     uint64
	Coinbase        common.Address
	BatchL2Data     []byte
	StateRoot       common.Hash
	LocalExitRoot   common.Hash
	AccInputHash    common.Hash
	L1InfoTreeIndex uint32
	L1InfoRoot      common.Hash
	// Timestamp (<=incaberry) -> batch time
	// 			 (>incaberry) -> minTimestamp used in batch creation, real timestamp is in virtual_batch.batch_timestamp
	Timestamp      time.Time
	Transactions   []types.Transaction
	GlobalExitRoot common.Hash
	ForcedBatchNum *uint64
	Resources      BatchResources
	// WIP: if WIP == true is a openBatch
	WIP     bool
	ChainID uint64
	ForkID  uint64
	Type    datastream.BatchType
}

Batch struct

type BatchRawV2

type BatchRawV2 struct {
	Blocks []L2BlockRaw
}

BatchRawV2 is the representation of a batch of transactions.

func DecodeBatchV2

func DecodeBatchV2(txsData []byte) (*BatchRawV2, error)

DecodeBatchV2 decodes a batch of transactions from a byte slice.

func (*BatchRawV2) String

func (b *BatchRawV2) String() string

type BatchResources

type BatchResources struct {
	ZKCounters ZKCounters
	Bytes      uint64
}

BatchResources is a struct that contains the ZKEVM resources used by a batch/tx

type BatchV2Encoder

type BatchV2Encoder struct {
	// contains filtered or unexported fields
}

BatchV2Encoder is a builder of the batchl2data used by EncodeBatchV2

func NewBatchV2Encoder

func NewBatchV2Encoder() *BatchV2Encoder

NewBatchV2Encoder creates a new BatchV2Encoder.

func (*BatchV2Encoder) AddBlockHeader

func (b *BatchV2Encoder) AddBlockHeader(l2BlockHeader ChangeL2BlockHeader)

AddBlockHeader adds a block header to the batch.

func (*BatchV2Encoder) AddTransaction

func (b *BatchV2Encoder) AddTransaction(transaction *L2TxRaw) error

AddTransaction adds a transaction to the batch.

func (*BatchV2Encoder) AddTransactions

func (b *BatchV2Encoder) AddTransactions(transactions []L2TxRaw) error

AddTransactions adds a set of transactions to the batch.

func (*BatchV2Encoder) GetResult

func (b *BatchV2Encoder) GetResult() []byte

GetResult returns the batch data.

type ChangeL2BlockHeader

type ChangeL2BlockHeader struct {
	DeltaTimestamp  uint32
	IndexL1InfoTree uint32
}

ChangeL2BlockHeader is the header of a L2 block.

func (ChangeL2BlockHeader) Encode

func (c ChangeL2BlockHeader) Encode(batchData []byte) []byte

Encode encodes a batch of l2blocks header into a byte slice.

type Config

type Config struct {
	// ChainID is the L2 ChainID provided by the Network Config
	ChainID uint64
	// DB is the database configuration
	DB db.Config `mapstructure:"DB"`
}

Config is state config

type DBBatch

type DBBatch struct {
	Batch      Batch
	Datastream []byte
	Witness    []byte
}

DBBatch struct is a wrapper for the state.Batch and its metadata

type ForcedBatchRawV2

type ForcedBatchRawV2 struct {
	Transactions []L2TxRaw
}

ForcedBatchRawV2 is the representation of a forced batch of transactions.

func DecodeForcedBatchV2

func DecodeForcedBatchV2(txsData []byte) (*ForcedBatchRawV2, error)

DecodeForcedBatchV2 decodes a forced batch V2 (Etrog) Is forbidden changeL2Block, so are just the set of transactions

type Genesis

type Genesis struct {
	// BlockNumber is the block number where the polygonZKEVM smc was deployed on L1
	BlockNumber uint64
	// Root hash of the genesis block
	Root common.Hash
	// Actions is the data to populate into the state trie
	Actions []*GenesisAction
}

Genesis contains the information to populate state on creation

type GenesisAction

type GenesisAction struct {
	Address         string `json:"address"`
	Type            int    `json:"type"`
	StoragePosition string `json:"storagePosition"`
	Bytecode        string `json:"bytecode"`
	Key             string `json:"key"`
	Value           string `json:"value"`
	Root            string `json:"root"`
}

GenesisAction represents one of the values set on the SMT during genesis.

type L2BlockRaw

type L2BlockRaw struct {
	BlockNumber uint64
	ChangeL2BlockHeader
	Transactions []L2TxRaw
}

L2BlockRaw is the raw representation of a L2 block.

type L2TxRaw

type L2TxRaw struct {
	EfficiencyPercentage uint8              // valid always
	TxAlreadyEncoded     bool               // If true the tx is already encoded (data field is used)
	Tx                   *types.Transaction // valid if TxAlreadyEncoded == false
	Data                 []byte             // valid if TxAlreadyEncoded == true
}

L2TxRaw is the raw representation of a L2 transaction inside a L2 block.

func DecodeTxRLP

func DecodeTxRLP(txsData []byte, offset int) (int, *L2TxRaw, error)

DecodeTxRLP decodes a transaction from a byte slice.

func (L2TxRaw) Encode

func (tx L2TxRaw) Encode(batchData []byte) ([]byte, error)

Encode encodes a transaction into a byte slice.

type Proof

type Proof struct {
	BatchNumber      uint64
	BatchNumberFinal uint64
	Proof            string
	InputProver      string
	ProofID          *string
	// Prover name, unique identifier across prover reboots.
	Prover *string
	// ProverID prover process identifier.
	ProverID *string
	// GeneratingSince holds the timestamp for the moment in which the
	// proof generation has started by a prover. Nil if the proof is not
	// currently generating.
	GeneratingSince *time.Time
	CreatedAt       time.Time
	UpdatedAt       time.Time
}

Proof struct

type Sequence

type Sequence struct {
	FromBatchNumber uint64
	ToBatchNumber   uint64
}

Sequence represents the sequence interval

type State

type State struct {
	// contains filtered or unexported fields
}

State is an implementation of the state

func NewState

func NewState(cfg Config, storage storage) *State

NewState creates a new State

func (*State) BeginStateTransaction

func (s *State) BeginStateTransaction(ctx context.Context) (pgx.Tx, error)

BeginStateTransaction starts a state transaction

type ZKCounters

type ZKCounters struct {
	GasUsed              uint64
	UsedKeccakHashes     uint32
	UsedPoseidonHashes   uint32
	UsedPoseidonPaddings uint32
	UsedMemAligns        uint32
	UsedArithmetics      uint32
	UsedBinaries         uint32
	UsedSteps            uint32
	UsedSha256Hashes_V2  uint32 //nolint:stylecheck
}

ZKCounters counters for the tx

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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