types

package
v0.0.0-...-ff78b6e Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LegacyTxType     byte = 0
	AccessListTxType byte = 1 // EIP-2930
	DynamicFeeTxType byte = 2 // EIP-1559
	BlobTxType       byte = 3 // EIP-4844
)

Variables

View Source
var ErrAlreadyKnown = errors.New("already known")
View Source
var ErrParseTxn = fmt.Errorf("%w transaction", rlp.ErrParse)
View Source
var ErrRejected = errors.New("rejected")
View Source
var ErrRlpTooBig = errors.New("txn rlp too big")
View Source
var TxParseMainnetTests = []parseTxTest{

	{PayloadStr: "f86a808459682f0082520894fe3b557e8fb62b89f4916b721be55ceb828dbd73872386f26fc10000801ca0d22fc3eed9b9b9dbef9eec230aa3fb849eff60356c6b34e86155dca5c03554c7a05e3903d7375337f103cb9583d97a59dcca7472908c31614ae240c6a8311b02d6",
		SenderStr: "fe3b557e8fb62b89f4916b721be55ceb828dbd73", IdHashStr: "595e27a835cd79729ff1eeacec3120eeb6ed1464a04ec727aaca734ead961328",
		SignHashStr: "e2b043ecdbcfed773fe7b5ffc2e23ec238081c77137134a06d71eedf9cdd81d3", Nonce: 0},

	{PayloadStr: "02f86a0180843b9aca00843b9aca0082520894e80d2a018c813577f33f9e69387dc621206fb3a48080c001a02c73a04cd144e5a84ceb6da942f83763c2682896b51f7922e2e2f9a524dd90b7a0235adda5f87a1d098e2739e40e83129ff82837c9042e6ad61d0481334dcb6f1a",
		SenderStr: "81f5daee2c61807d0fc5e4c8b4e1d3c3e028d9ab", IdHashStr: "b4a8cd0b91310b0f84216c834c4cfa25a4ffc116b54692ac1f4e682be7fa73c9",
		SignHashStr: "c63673a5d989925d01a6c1339252f546e99b6957ce566a488154e169ae9bd49c", Nonce: 0},
	{PayloadStr: "01f86b01018203e882520894236ff1e97419ae93ad80cafbaa21220c5d78fb7d880de0b6b3a764000080c080a0987e3d8d0dcd86107b041e1dca2e0583118ff466ad71ad36a8465dd2a166ca2da02361c5018e63beea520321b290097cd749febc2f437c7cb41fdd085816742060",
		SenderStr: "91406aebf7370d6db8d1796bc8fe97ca4b6bed78", IdHashStr: "7edf4b1a1594b252eb80edcf51605eb1a3b17ccdf891b303a8be146269821b65",
		SignHashStr: "ae2a02407f345601507c52d1af6a89bafd4622fbcdac0001272ebca42cf7f7c2", Nonce: 1},
	{PayloadStr: "f86780862d79883d2000825208945df9b87991262f6ba471f09758cde1c0fc1de734827a69801ca088ff6cf0fefd94db46111149ae4bfc179e9b94721fffd821d38d16464b3f71d0a045e0aff800961cfce805daef7016b9b675c137a6a41a548f7b60a3484c06a33a",
		SenderStr: "a1e4380a3b1f749673e270229993ee55f35663b4", IdHashStr: "5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060",
		SignHashStr: "19b1e28c14f33e74b96b88eba97d4a4fc8a97638d72e972310025b7e1189b049", Nonce: 0},
	{PayloadStr: "b903a301f9039f018218bf85105e34df0083048a949410a0847c2d170008ddca7c3a688124f49363003280b902e4c11695480000000000000000000000004b274e4a9af31c20ed4151769a88ffe63d9439960000000000000000000000008510211a852f0c5994051dd85eaef73112a82eb5000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000bad4de000000000000000000000000607816a600000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000001146aa2600000000000000000000000000000000000000000000000000000000000001bc9b000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000482579f93dc13e6b434e38b5a0447ca543d88a4600000000000000000000000000000000000000000000000000000000000000c42df546f40000000000000000000000004b274e4a9af31c20ed4151769a88ffe63d943996000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000007d93f93d41604572119e4be7757a7a4a43705f080000000000000000000000000000000000000000000000003782dace9d90000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082b5a61569b5898ac347c82a594c86699f1981aa88ca46a6a00b8e4f27b3d17bdf3714e7c0ca6a8023b37cca556602fce7dc7daac3fcee1ab04bbb3b94c10dec301cc57266db6567aa073efaa1fa6669bdc6f0877b0aeab4e33d18cb08b8877f08931abf427f11bade042177db48ca956feb114d6f5d56d1f5889047189562ec545e1c000000000000000000000000000000000000000000000000000000000000f84ff7946856ccf24beb7ed77f1f24eee5742f7ece5557e2e1a00000000000000000000000000000000000000000000000000000000000000001d694b1dd690cc9af7bb1a906a9b5a94f94191cc553cec080a0d52f3dbcad3530e73fcef6f4a75329b569a8903bf6d8109a960901f251a37af3a00ecf570e0c0ffa6efdc6e6e49be764b6a1a77e47de7bb99e167544ffbbcd65bc",
		SenderStr: "1ced2cef30d40bb3617f8d455071b69f3b12d06f", IdHashStr: "851bad0415758075a1eb86776749c829b866d43179c57c3e4a4b9359a0358231",
		SignHashStr: "894d999ea27537def37534b3d55df3fed4e1492b31e9f640774432d21cf4512c", Nonce: 6335},
	{PayloadStr: "02f8cf01038502540be40085174876e8008301869f94e77162b7d2ceb3625a4993bab557403a7b706f18865af3107a400080f85bf85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000000780a0f73da48f3f5c9f324dfd28d106dcf911b53f33c92ae068cf6135352300e7291aa06ee83d0f59275d90000ac8cf912c6eb47261d244c9db19ffefc49e52869ff197",
		SenderStr: "e252dd9e8b19f4bcdc0f542e04e732fed2047f00", IdHashStr: "f08b9885d48a1307c5d5841fb2f92adaa35815846ac071cba65376ccfbc99c5d",
		SignHashStr: "aeda585cd1f1dc0812d7c9ef0396fe3fb9102c9b927a14724180d4616f4568f2", Nonce: 3},

	{PayloadStr: "01f889018201f30a8301e241808080f838f7940000000000000000000000000000000000000001e1a0000000000000000000000000000000000000000000000000000000000000000080a0a2196512ef8325b781e32d96d283a9d4cf3946947da77f3cd310eee050c537d5a00144af5513a24363bf49abed9a25476cb7c33df6e0c0053b63ee8dac64b027aa",
		SenderStr: "4d8286232b1f058d8bdb1702d0f6a1e887ced385", IdHashStr: "bde66bd7925917db9e49e38a12ed0dcd6f9422f8db90de26d34a4523f8861d1e",
		SignHashStr: "7f69febd06ddc1e72d9cd34524c82b3a8a116a02a10757be34cf536d6992d51c", Nonce: 499},
	{PayloadStr: "01f84b01018080808080c080a0382d06e968cc18373209a2532b2c9df494c36475e479020730c918b1b6f73f6ba0084b433c82339de844e2531363f59fa64218e965016cc55069828d88959b58fe", Nonce: 1},
}

Functions

func DecodeSender

func DecodeSender(enc []byte) (nonce uint64, balance uint256.Int, err error)

Decode the sender's balance and nonce from encoded byte-slice

func EncodeGetPooledTransactions66

func EncodeGetPooledTransactions66(hashes []byte, requestID uint64, encodeBuf []byte) ([]byte, error)

EncodeGetPooledTransactions66 produces encoding of GetPooledTransactions66 packet

func EncodeHashes

func EncodeHashes(hashes []byte, encodeBuf []byte) []byte

EncodeHashes produces RLP encoding of given number of hashes, as RLP list It appends encoding to the given given slice (encodeBuf), reusing the space there is there is enough capacity. The first returned value is the slice where encodinfg

func EncodePooledTransactions66

func EncodePooledTransactions66(txsRlp [][]byte, requestID uint64, encodeBuf []byte) []byte

TODO(eip-4844) wrappedWithBlobs = true?

func EncodeSender

func EncodeSender(nonce uint64, balance uint256.Int, buffer []byte)

Encode the details of txn sender into the given "buffer" byte-slice that should be big enough

func EncodeSenderLengthForStorage

func EncodeSenderLengthForStorage(nonce uint64, balance uint256.Int) uint

func EncodeTransactions

func EncodeTransactions(txsRlp [][]byte, encodeBuf []byte) []byte

TODO(eip-4844) wrappedWithBlobs = false?

func ParseGetPooledTransactions66

func ParseGetPooledTransactions66(payload []byte, pos int, hashbuf []byte) (requestID uint64, hashes []byte, newPos int, err error)

func ParseHash

func ParseHash(payload []byte, pos int, hashbuf []byte) ([]byte, int, error)

ParseHash extracts the next hash from the RLP encoding (payload) from a given position. It appends the hash to the given slice, reusing the space if there is enough capacity The first returned value is the slice where hash is appended to. The second returned value is the new position in the RLP payload after the extraction of the hash.

func ParseHashesCount

func ParseHashesCount(payload []byte, pos int) (count int, dataPos int, err error)

ParseHashesCount looks at the RLP length Prefix for list of 32-byte hashes and returns number of hashes in the list to expect

func ParsePooledTransactions66

func ParsePooledTransactions66(payload []byte, pos int, ctx *TxParseContext, txSlots *TxSlots, validateHash func([]byte) error) (requestID uint64, newPos int, err error)

func ParseTransactions

func ParseTransactions(payload []byte, pos int, ctx *TxParseContext, txSlots *TxSlots, validateHash func([]byte) error) (newPos int, err error)

func PeekTransactionType

func PeekTransactionType(serialized []byte) (byte, error)

Types

type AccessList

type AccessList []AccessTuple

AccessList is an EIP-2930 access list.

func (AccessList) StorageKeys

func (al AccessList) StorageKeys() int

StorageKeys returns the total number of storage keys in the access list.

type AccessTuple

type AccessTuple struct {
	Address     common.Address `json:"address"`
	StorageKeys []common.Hash  `json:"storageKeys"`
}

AccessTuple is the element type of an access list.

type Addresses

type Addresses []byte // flatten list of 20-byte addresses

func (Addresses) AddressAt

func (h Addresses) AddressAt(i int) common.Address

AddressAt returns an address at the given index in the flattened list. Use this method if you want to reduce memory allocations

func (Addresses) At

func (h Addresses) At(i int) []byte

func (Addresses) Len

func (h Addresses) Len() int

type Announcements

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

func (*Announcements) Append

func (a *Announcements) Append(t byte, size uint32, hash []byte)

func (*Announcements) AppendOther

func (a *Announcements) AppendOther(other Announcements)

func (Announcements) At

func (a Announcements) At(i int) (byte, uint32, []byte)

func (Announcements) Copy

func (a Announcements) Copy() Announcements

func (Announcements) DedupCopy

func (a Announcements) DedupCopy() Announcements

DedupCopy sorts hashes, and creates deduplicated copy

func (Announcements) DedupHashes

func (a Announcements) DedupHashes() Hashes

func (Announcements) Hashes

func (a Announcements) Hashes() Hashes

func (Announcements) Len

func (a Announcements) Len() int

func (Announcements) Less

func (a Announcements) Less(i, j int) bool

func (*Announcements) Reset

func (a *Announcements) Reset()

func (Announcements) Swap

func (a Announcements) Swap(i, j int)

type Hashes

type Hashes []byte // flatten list of 32-byte hashes

func (Hashes) At

func (h Hashes) At(i int) []byte

func (Hashes) DedupCopy

func (h Hashes) DedupCopy() Hashes

DedupCopy sorts hashes, and creates deduplicated copy

func (Hashes) Len

func (h Hashes) Len() int

func (Hashes) Less

func (h Hashes) Less(i, j int) bool

func (Hashes) Swap

func (h Hashes) Swap(i, j int)

type NewPooledTransactionHashesPacket

type NewPooledTransactionHashesPacket [][length.Hash]byte

type PeerID

type PeerID *types.H512

type TxParseConfig

type TxParseConfig struct {
	ChainID uint256.Int
}

type TxParseContext

type TxParseContext struct {
	Keccak2 hash.Hash
	Keccak1 hash.Hash

	ChainID       uint256.Int // Signature values
	R             uint256.Int // Signature values
	S             uint256.Int // Signature values
	V             uint256.Int // Signature values
	ChainIDMul    uint256.Int
	DeriveChainID uint256.Int // pre-allocated variable to calculate Sub(&ctx.v, &ctx.chainIDMul)

	Sig     [65]byte
	Sighash [32]byte

	IsProtected bool
	// contains filtered or unexported fields
}

TxParseContext is object that is required to parse transactions and turn transaction payload into TxSlot objects usage of TxContext helps avoid extra memory allocations

func NewTxParseContext

func NewTxParseContext(chainID uint256.Int) *TxParseContext

func (*TxParseContext) ChainIDRequired

func (ctx *TxParseContext) ChainIDRequired() *TxParseContext

Set ChainID-Required flag in the Parse context and return it

func (*TxParseContext) ParseTransaction

func (ctx *TxParseContext) ParseTransaction(payload []byte, pos int, slot *TxSlot, sender []byte, hasEnvelope, wrappedWithBlobs bool, validateHash func([]byte) error) (p int, err error)

ParseTransaction extracts all the information from the transactions's payload (RLP) necessary to build TxSlot. It also performs syntactic validation of the transactions. wrappedWithBlobs means that for blob (type 3) transactions the full version with blobs/commitments/proofs is expected (see https://eips.ethereum.org/EIPS/eip-4844#networking).

func (*TxParseContext) ValidateRLP

func (ctx *TxParseContext) ValidateRLP(f func(txnRlp []byte) error)

Set the RLP validate function

func (*TxParseContext) WithAllowPreEip2s

func (ctx *TxParseContext) WithAllowPreEip2s(v bool)

Set the AllowPreEIP2s flag

func (*TxParseContext) WithSender

func (ctx *TxParseContext) WithSender(v bool)

Set the with sender flag

type TxSlot

type TxSlot struct {
	Rlp            []byte      // Is set to nil after flushing to db, frees memory, later we look for it in the db, if needed
	Value          uint256.Int // Value transferred by the transaction
	Tip            uint256.Int // Maximum tip that transaction is giving to miner/block proposer
	FeeCap         uint256.Int // Maximum fee that transaction burns and gives to the miner/block proposer
	SenderID       uint64      // SenderID - require external mapping to it's address
	Nonce          uint64      // Nonce of the transaction
	DataLen        int         // Length of transaction's data (for calculation of intrinsic gas)
	DataNonZeroLen int
	AlAddrCount    int      // Number of addresses in the access list
	AlStorCount    int      // Number of storage keys in the access list
	Gas            uint64   // Gas limit of the transaction
	IDHash         [32]byte // Transaction hash for the purposes of using it as a transaction Id
	Traced         bool     // Whether transaction needs to be traced throughout transaction pool code and generate debug printing
	Creation       bool     // Set to true if "To" field of the transaction is not set
	Type           byte     // Transaction type
	Size           uint32   // Size of the payload (without the RLP string envelope for typed transactions)

	// EIP-4844: Shard Blob Transactions
	BlobFeeCap  uint256.Int // max_fee_per_blob_gas
	BlobHashes  []common.Hash
	Blobs       [][]byte
	Commitments []gokzg4844.KZGCommitment
	Proofs      []gokzg4844.KZGProof
}

TxSlot contains information extracted from an Ethereum transaction, which is enough to manage it inside the transaction. Also, it contains some auxillary information, like ephemeral fields, and indices within priority queues

func (*TxSlot) PrintDebug

func (tx *TxSlot) PrintDebug(prefix string)

nolint

type TxSlots

type TxSlots struct {
	Txs     []*TxSlot
	Senders Addresses
	IsLocal []bool
}

func (*TxSlots) Append

func (s *TxSlots) Append(slot *TxSlot, sender []byte, isLocal bool)

func (*TxSlots) Resize

func (s *TxSlots) Resize(targetSize uint)

Resize internal arrays to len=targetSize, shrinks if need. It rely on `append` algorithm to realloc

func (*TxSlots) Valid

func (s *TxSlots) Valid() error

type TxsRlp

type TxsRlp struct {
	Txs     [][]byte
	Senders Addresses
	IsLocal []bool
}

func (*TxsRlp) Resize

func (s *TxsRlp) Resize(targetSize uint)

Resize internal arrays to len=targetSize, shrinks if need. It rely on `append` algorithm to realloc

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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