diff --git a/core/types/block.go b/core/types/block.go index dc53b1df06..a792bcf9fe 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -85,7 +85,11 @@ type Header struct { Nonce BlockNonce `json:"nonce"` // BaseFee was added by EIP-1559 and is ignored in legacy headers. - BaseFee *big.Int `json:"baseFeePerGas" rlp:"optional"` + BaseFee *big.Int `json:"baseFeePerGas" rlp:"optional"` + // Codeword was added by Worldlandhardfork and is ignored in legacy headers. + Codeword []byte `json:"codeword" rlp:"optional"` + // CodeLength was added by Worldlandhardfork and is ignored in legacy headers. + CodeLength uint64 `json:"codelength" rlp:"optional"` /* TODO (MariusVanDerWijden) Add this field once needed @@ -103,6 +107,8 @@ type headerMarshaling struct { Time hexutil.Uint64 Extra hexutil.Bytes BaseFee *hexutil.Big + //Codeword hexutil.Bytes + //CodeLength hexutil.Uint64 Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON } @@ -117,6 +123,7 @@ var headerSize = common.StorageSize(reflect.TypeOf(Header{}).Size()) // Size returns the approximate memory used by all internal contents. It is used // to approximate and limit the memory consumption of various caches. func (h *Header) Size() common.StorageSize { + //return headerSize + common.StorageSize(len(h.Codeword)+len(h.Extra)+(h.Difficulty.BitLen()+h.Number.BitLen())/8) return headerSize + common.StorageSize(len(h.Extra)+(h.Difficulty.BitLen()+h.Number.BitLen())/8) } @@ -141,6 +148,9 @@ func (h *Header) SanityCheck() error { return fmt.Errorf("too large base fee: bitlen %d", bfLen) } } + + //maybe add codeword? + return nil } @@ -248,6 +258,13 @@ func CopyHeader(h *Header) *Header { cpy.Extra = make([]byte, len(h.Extra)) copy(cpy.Extra, h.Extra) } + /*if len(h.Codeword) > 0 { + cpy.Codeword = make([]byte, len(h.Codeword)) + copy(cpy.Codeword, h.Codeword) + } + if h.CodeLength != nil { + cpy.BaseFee = new(big.Int).Set(h.CodeLength) + }*/ return &cpy } @@ -304,6 +321,17 @@ func (b *Block) ReceiptHash() common.Hash { return b.header.ReceiptHash } func (b *Block) UncleHash() common.Hash { return b.header.UncleHash } func (b *Block) Extra() []byte { return common.CopyBytes(b.header.Extra) } +func (b *Block) Codeword() []byte { + if b.header.Codeword == nil { + return nil + } + return common.CopyBytes(b.header.Codeword) +} + +func (b *Block) CodeLength() uint64 { + return b.header.CodeLength +} + func (b *Block) BaseFee() *big.Int { if b.header.BaseFee == nil { return nil diff --git a/core/types/gen_header_json.go b/core/types/gen_header_json.go index ce36aad320..c116aac24b 100644 --- a/core/types/gen_header_json.go +++ b/core/types/gen_header_json.go @@ -31,8 +31,11 @@ func (h Header) MarshalJSON() ([]byte, error) { Extra hexutil.Bytes `json:"extraData" gencodec:"required"` MixDigest common.Hash `json:"mixHash"` Nonce BlockNonce `json:"nonce"` - BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` + BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` Hash common.Hash `json:"hash"` + Codeword hexutil.Bytes `json:"codeword" rlp:"optional"` + CodeLength hexutil.Uint64 `json:"codelength" rlp:"optional"` + } var enc Header enc.ParentHash = h.ParentHash @@ -52,6 +55,8 @@ func (h Header) MarshalJSON() ([]byte, error) { enc.Nonce = h.Nonce enc.BaseFee = (*hexutil.Big)(h.BaseFee) enc.Hash = h.Hash() + enc.Codeword = h.Codeword + enc.CodeLength = hexutil.Uint64(h.CodeLength) return json.Marshal(&enc) } @@ -73,7 +78,9 @@ func (h *Header) UnmarshalJSON(input []byte) error { Extra *hexutil.Bytes `json:"extraData" gencodec:"required"` MixDigest *common.Hash `json:"mixHash"` Nonce *BlockNonce `json:"nonce"` - BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` + BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` + Codeword *hexutil.Bytes `json:"codeword" rlp:"optional"` + CodeLength *hexutil.Uint64 `json:"codelength" rlp:"optional"` } var dec Header if err := json.Unmarshal(input, &dec); err != nil { @@ -139,5 +146,12 @@ func (h *Header) UnmarshalJSON(input []byte) error { if dec.BaseFee != nil { h.BaseFee = (*big.Int)(dec.BaseFee) } + if dec.Codeword == nil { + h.Codeword = *dec.Codeword + } + if dec.CodeLength == nil { + h.CodeLength = uint64(*dec.CodeLength) + } + return nil } diff --git a/core/types/gen_header_rlp.go b/core/types/gen_header_rlp.go index 36d246ee9a..41ae26e970 100644 --- a/core/types/gen_header_rlp.go +++ b/core/types/gen_header_rlp.go @@ -34,6 +34,7 @@ func (obj *Header) EncodeRLP(_w io.Writer) error { } w.WriteBigInt(obj.Number) } + w.WriteUint64(obj.GasLimit) w.WriteUint64(obj.GasUsed) w.WriteUint64(obj.Time) @@ -51,6 +52,17 @@ func (obj *Header) EncodeRLP(_w io.Writer) error { w.WriteBigInt(obj.BaseFee) } } + _tmp2 := obj.Codeword != nil + if _tmp2 { + if obj.Codeword == nil { + w.Write(rlp.EmptyString) + } else { + w.WriteBytes(obj.Codeword) + } + } + if obj.CodeLength != 0 { + w.WriteUint64(obj.CodeLength) + } w.ListEnd(_tmp0) return w.Flush() }