Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix monitor for avalanche #103

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions go-ethereum/core/types/access_list_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type AccessListTx struct {
Data []byte // contract invocation input data
AccessList AccessList // EIP-2930 access list
V, R, S *big.Int // signature values

// Optional Avalanche extension
From *common.Address
}

// copy creates a deep copy of the transaction data and initializes all fields.
Expand All @@ -62,6 +65,7 @@ func (tx *AccessListTx) copy() TxData {
To: copyAddressPtr(tx.To),
Data: common.CopyBytes(tx.Data),
Gas: tx.Gas,
From: copyAddressPtr(tx.From),
// These are copied below.
AccessList: make(AccessList, len(tx.AccessList)),
Value: new(big.Int),
Expand Down
46 changes: 45 additions & 1 deletion go-ethereum/core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func (n *BlockNonce) UnmarshalText(input []byte) error {

// Header represents a block header in the Ethereum blockchain.
type Header struct {
hash *common.Hash

ParentHash common.Hash `json:"parentHash" gencodec:"required"`
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
Coinbase common.Address `json:"miner"`
Expand All @@ -84,13 +86,21 @@ type Header struct {
BaseFee *big.Int `json:"baseFeePerGas" rlp:"optional"`

// WithdrawalsHash was added by EIP-4895 and is ignored in legacy headers.
WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"`
WithdrawalsHash *common.Hash `json:"withdrawalsRoot,omitempty" rlp:"optional"`

/*
TODO (MariusVanDerWijden) Add this field once needed
// Random was added during the merge and contains the BeaconState randomness
Random common.Hash `json:"random" rlp:"optional"`
*/

// Optional Avalanche extension
ExtSize *uint64 `json:"size,omitempty" rlp:"optional"`
ExtTotalDifficulty *big.Int `json:"totalDifficulty,omitempty" rlp:"optional"`
ExtBlockExtraData []byte `json:"blockExtraData,omitempty" rlp:"optional"`
ExtBlockGasCost *uint64 `json:"blockGasCost,omitempty" rlp:"optional"`
ExtDataGasUsed *uint64 `json:"extDataGasUsed,omitempty" rlp:"optional"`
ExtDataHash *common.Hash `json:"extDataHash,omitempty" rlp:"optional"`
}

// field type overrides for gencodec
Expand All @@ -103,6 +113,12 @@ type headerMarshaling struct {
Extra hexutil.Bytes
BaseFee *hexutil.Big
Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON

ExtSize *hexutil.Uint64
ExtTotalDifficulty *hexutil.Big
ExtBlockExtraData hexutil.Bytes
ExtBlockGasCost *hexutil.Uint64
ExtDataGasUsed *hexutil.Uint64
}

// Hash returns the block hash of the header, which is simply the keccak256 hash of its
Expand All @@ -123,6 +139,10 @@ func (h *Header) Hash() common.Hash {
// computed block hash: 0xcfe3a3725b81644c8fd38ced1acbf2c74e000087477b151bfc73217e025104ba
// real block hash: 0xfcbe02c3303094a6ef511ed6acb39931f24c70691a0afefa740b7a3aed678861

if h.hash != nil {
return *h.hash
}

return rlpHash(h)
}

Expand Down Expand Up @@ -299,6 +319,29 @@ func CopyHeader(h *Header) *Header {
cpy.WithdrawalsHash = new(common.Hash)
*cpy.WithdrawalsHash = *h.WithdrawalsHash
}
if h.ExtSize != nil {
cpy.ExtSize = new(uint64)
*cpy.ExtSize = *h.ExtSize
}
if h.ExtTotalDifficulty != nil {
cpy.ExtTotalDifficulty = new(big.Int).Set(h.ExtTotalDifficulty)
}
if len(h.ExtBlockExtraData) > 0 {
cpy.ExtBlockExtraData = make([]byte, len(h.ExtBlockExtraData))
copy(cpy.ExtBlockExtraData, h.ExtBlockExtraData)
}
if h.ExtBlockGasCost != nil {
cpy.ExtBlockGasCost = new(uint64)
*cpy.ExtBlockGasCost = *h.ExtBlockGasCost
}
if h.ExtDataGasUsed != nil {
cpy.ExtDataGasUsed = new(uint64)
*cpy.ExtDataGasUsed = *h.ExtDataGasUsed
}
if h.ExtDataHash != nil {
cpy.ExtDataHash = new(common.Hash)
*cpy.ExtDataHash = *h.ExtDataHash
}
return &cpy
}

Expand Down Expand Up @@ -441,6 +484,7 @@ func (b *Block) WithWithdrawals(withdrawals []*Withdrawal) *Block {
// delete this code ASAP, this shouldn't be neccesary
func (b *Block) SetHash(hash common.Hash) {
b.hash.Store(hash)
b.header.hash = &hash
}

// Hash returns the keccak256 hash of b's header.
Expand Down
4 changes: 4 additions & 0 deletions go-ethereum/core/types/dynamic_fee_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type DynamicFeeTx struct {
V *big.Int `json:"v" gencodec:"required"`
R *big.Int `json:"r" gencodec:"required"`
S *big.Int `json:"s" gencodec:"required"`

// Optional Avalanche extension
From *common.Address
}

// copy creates a deep copy of the transaction data and initializes all fields.
Expand All @@ -46,6 +49,7 @@ func (tx *DynamicFeeTx) copy() TxData {
To: copyAddressPtr(tx.To),
Data: common.CopyBytes(tx.Data),
Gas: tx.Gas,
From: copyAddressPtr(tx.From),
// These are copied below.
AccessList: make(AccessList, len(tx.AccessList)),
Value: new(big.Int),
Expand Down
106 changes: 71 additions & 35 deletions go-ethereum/core/types/gen_header_json.go

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

51 changes: 49 additions & 2 deletions go-ethereum/core/types/gen_header_rlp.go

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

9 changes: 9 additions & 0 deletions go-ethereum/core/types/legacy_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ type LegacyTx struct {
Value *big.Int // wei amount
Data []byte // contract invocation input data
V, R, S *big.Int // signature values

// Optional Avalanche extension:
From *common.Address
ChainID *big.Int
}

// NewTransaction creates an unsigned legacy transaction.
Expand Down Expand Up @@ -65,12 +69,14 @@ func (tx *LegacyTx) copy() TxData {
To: copyAddressPtr(tx.To),
Data: common.CopyBytes(tx.Data),
Gas: tx.Gas,
From: copyAddressPtr(tx.From),
// These are initialized below.
Value: new(big.Int),
GasPrice: new(big.Int),
V: new(big.Int),
R: new(big.Int),
S: new(big.Int),
ChainID: new(big.Int),
}
if tx.Value != nil {
cpy.Value.Set(tx.Value)
Expand All @@ -87,6 +93,9 @@ func (tx *LegacyTx) copy() TxData {
if tx.S != nil {
cpy.S.Set(tx.S)
}
if tx.ChainID != nil {
cpy.ChainID.Set(tx.ChainID)
}
return cpy
}

Expand Down
Loading
Loading