block.Header is now a lightweight wrapper around an embedded HeaderInterface value, which is implemented by both v0 and v1 headers. It inherits all methods from the wrapped HeaderInterface, except it overrides EncodeRLP, DecodeRLP, and Hash to handle tagged-RLP encoding/decoding. (block.HeaderRegistry is the tagged RLP registry for versioned headers.) A ripple effect is that header instance creation now requires knowledge of epoch. This logic is handled by blockfactory. blockfactory.Factory is the interface, implemented by blockfactory.factory type. It uses a chain config to pull in the right epoch for the right type. As a convenience, blockfactory.NewTestHeader creates a new test-purpose headers. Use this in contexts where the implied chain config is TestChainConfig or the chain config does not matter. Miscellaneous changes: - block.HeaderFieldSetter now lives in its own file. - The functionality of block.NewHeaderWith has been replaced by the (*block.Header).With method. The accompanying unit tests for (*block.Header).EncodeRLP and (*block.Header).DecodeRLP() are the cross-sectional unit tests for the functionality added by this. They make sure that v0 header is encoded/decoded without tagged RLP envelope (compatibility mode), and v1 header is encoded/decoded with one. See comments of the RLP byte sequence for differences.pull/1538/head
parent
df76865cd3
commit
8ac058bb2e
@ -0,0 +1,49 @@ |
||||
package blockfactory |
||||
|
||||
import ( |
||||
"math/big" |
||||
|
||||
"github.com/harmony-one/harmony/block" |
||||
"github.com/harmony-one/harmony/block/v0" |
||||
"github.com/harmony-one/harmony/block/v1" |
||||
"github.com/harmony-one/harmony/internal/params" |
||||
) |
||||
|
||||
// Factory is a data structure factory for a specific chain configuration.
|
||||
type Factory interface { |
||||
// NewHeader creates a new, empty header object for the given epoch.
|
||||
NewHeader(epoch *big.Int) *block.Header |
||||
} |
||||
|
||||
type factory struct { |
||||
chainConfig *params.ChainConfig |
||||
} |
||||
|
||||
// NewFactory creates a new factory for the given chain configuration.
|
||||
func NewFactory(chainConfig *params.ChainConfig) Factory { |
||||
return &factory{chainConfig: chainConfig} |
||||
} |
||||
|
||||
func (f *factory) NewHeader(epoch *big.Int) *block.Header { |
||||
var impl block.HeaderInterface |
||||
switch { |
||||
case epoch.Cmp(f.chainConfig.CrossLinkEpoch) >= 0: |
||||
impl = v1.NewHeader() |
||||
default: |
||||
impl = v0.NewHeader() |
||||
} |
||||
return &block.Header{impl} |
||||
} |
||||
|
||||
// Factories corresponding to well-known chain configurations.
|
||||
var ( |
||||
ForTest = NewFactory(params.TestChainConfig) |
||||
ForTestnet = NewFactory(params.TestnetChainConfig) |
||||
ForMainnet = NewFactory(params.MainnetChainConfig) |
||||
) |
||||
|
||||
// NewTestHeader creates a new, empty header object for epoch 0 using the test
|
||||
// factory. Use for unit tests.
|
||||
func NewTestHeader() *block.Header { |
||||
return ForTest.NewHeader(new(big.Int)) |
||||
} |
@ -1,209 +1,83 @@ |
||||
package block |
||||
|
||||
import ( |
||||
"math/big" |
||||
"io" |
||||
"reflect" |
||||
|
||||
"github.com/ethereum/go-ethereum/common" |
||||
ethtypes "github.com/ethereum/go-ethereum/core/types" |
||||
ethcommon "github.com/ethereum/go-ethereum/common" |
||||
"github.com/ethereum/go-ethereum/rlp" |
||||
"github.com/harmony-one/taggedrlp" |
||||
"github.com/pkg/errors" |
||||
"github.com/rs/zerolog" |
||||
|
||||
v0 "github.com/harmony-one/harmony/block/v0" |
||||
v1 "github.com/harmony-one/harmony/block/v1" |
||||
"github.com/harmony-one/harmony/crypto/hash" |
||||
) |
||||
|
||||
// Header represents a block header in the Harmony blockchain.
|
||||
type Header = v1.Header |
||||
|
||||
// NewHeader creates a new header object
|
||||
var NewHeader = v1.NewHeader |
||||
|
||||
// HeaderFieldSetter is a header field setter.
|
||||
//
|
||||
// See NewHeaderWith for how it is used.
|
||||
type HeaderFieldSetter struct { |
||||
h *Header |
||||
} |
||||
|
||||
// NewHeaderWith creates a new header and returns its field setter context.
|
||||
//
|
||||
// Call a chain of setters on the returned field setter, followed by a call of
|
||||
// Header method. Example:
|
||||
//
|
||||
// header := NewHeaderWith().
|
||||
// ParentHash(parent.Hash()).
|
||||
// Epoch(parent.Epoch()).
|
||||
// ShardID(parent.ShardID()).
|
||||
// Number(new(big.Int).Add(parent.Number(), big.NewInt(1)).
|
||||
// Header()
|
||||
func NewHeaderWith() *HeaderFieldSetter { |
||||
return (*HeaderFieldSetter)(&HeaderFieldSetter{h: NewHeader()}) |
||||
} |
||||
|
||||
// ParentHash sets the parent hash field.
|
||||
func (s HeaderFieldSetter) ParentHash(newParentHash common.Hash) HeaderFieldSetter { |
||||
s.h.SetParentHash(newParentHash) |
||||
return s |
||||
} |
||||
|
||||
// Coinbase sets the coinbase address field.
|
||||
func (s HeaderFieldSetter) Coinbase(newCoinbase common.Address) HeaderFieldSetter { |
||||
s.h.SetCoinbase(newCoinbase) |
||||
return s |
||||
} |
||||
|
||||
// Root sets the state trie root hash field.
|
||||
func (s HeaderFieldSetter) Root(newRoot common.Hash) HeaderFieldSetter { |
||||
s.h.SetRoot(newRoot) |
||||
return s |
||||
} |
||||
|
||||
// TxHash sets the transaction trie root hash field.
|
||||
func (s HeaderFieldSetter) TxHash(newTxHash common.Hash) HeaderFieldSetter { |
||||
s.h.SetTxHash(newTxHash) |
||||
return s |
||||
} |
||||
|
||||
// ReceiptHash sets the same-shard transaction receipt trie hash.
|
||||
func (s HeaderFieldSetter) ReceiptHash(newReceiptHash common.Hash) HeaderFieldSetter { |
||||
s.h.SetReceiptHash(newReceiptHash) |
||||
return s |
||||
} |
||||
|
||||
// OutgoingReceiptHash sets the egress transaction receipt trie hash.
|
||||
func (s HeaderFieldSetter) OutgoingReceiptHash(newOutgoingReceiptHash common.Hash) HeaderFieldSetter { |
||||
s.h.SetOutgoingReceiptHash(newOutgoingReceiptHash) |
||||
return s |
||||
} |
||||
|
||||
// IncomingReceiptHash sets the ingress transaction receipt trie hash.
|
||||
func (s HeaderFieldSetter) IncomingReceiptHash(newIncomingReceiptHash common.Hash) HeaderFieldSetter { |
||||
s.h.SetIncomingReceiptHash(newIncomingReceiptHash) |
||||
return s |
||||
} |
||||
|
||||
// Bloom sets the smart contract log Bloom filter for this block.
|
||||
func (s HeaderFieldSetter) Bloom(newBloom ethtypes.Bloom) HeaderFieldSetter { |
||||
s.h.SetBloom(newBloom) |
||||
return s |
||||
} |
||||
|
||||
// Number sets the block number.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) Number(newNumber *big.Int) HeaderFieldSetter { |
||||
s.h.SetNumber(newNumber) |
||||
return s |
||||
} |
||||
|
||||
// GasLimit sets the gas limit for transactions in this block.
|
||||
func (s HeaderFieldSetter) GasLimit(newGasLimit uint64) HeaderFieldSetter { |
||||
s.h.SetGasLimit(newGasLimit) |
||||
return s |
||||
} |
||||
|
||||
// GasUsed sets the amount of gas used by transactions in this block.
|
||||
func (s HeaderFieldSetter) GasUsed(newGasUsed uint64) HeaderFieldSetter { |
||||
s.h.SetGasUsed(newGasUsed) |
||||
return s |
||||
} |
||||
|
||||
// Time sets the UNIX timestamp of this block.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) Time(newTime *big.Int) HeaderFieldSetter { |
||||
s.h.SetTime(newTime) |
||||
return s |
||||
type Header struct { |
||||
HeaderInterface |
||||
} |
||||
|
||||
// Extra sets the extra data field of this block.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) Extra(newExtra []byte) HeaderFieldSetter { |
||||
s.h.SetExtra(newExtra) |
||||
return s |
||||
// EncodeRLP encodes the header using tagged RLP representation.
|
||||
func (h *Header) EncodeRLP(w io.Writer) error { |
||||
return HeaderRegistry.Encode(w, h.HeaderInterface) |
||||
} |
||||
|
||||
// MixDigest sets the mixhash of this block.
|
||||
func (s HeaderFieldSetter) MixDigest(newMixDigest common.Hash) HeaderFieldSetter { |
||||
s.h.SetMixDigest(newMixDigest) |
||||
return s |
||||
// DecodeRLP decodes the header using tagged RLP representation.
|
||||
func (h *Header) DecodeRLP(s *rlp.Stream) error { |
||||
decoded, err := HeaderRegistry.Decode(s) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
|
||||
// ViewID sets the view ID in which the block was originally proposed.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) ViewID(newViewID *big.Int) HeaderFieldSetter { |
||||
s.h.SetViewID(newViewID) |
||||
return s |
||||
hif, ok := decoded.(HeaderInterface) |
||||
if !ok { |
||||
return errors.Errorf( |
||||
"decoded object (type %s) does not implement HeaderInterface", |
||||
taggedrlp.TypeName(reflect.TypeOf(decoded))) |
||||
} |
||||
|
||||
// Epoch sets the epoch number of this block.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) Epoch(newEpoch *big.Int) HeaderFieldSetter { |
||||
s.h.SetEpoch(newEpoch) |
||||
return s |
||||
h.HeaderInterface = hif |
||||
return nil |
||||
} |
||||
|
||||
// ShardID sets the shard ID to which this block belongs.
|
||||
func (s HeaderFieldSetter) ShardID(newShardID uint32) HeaderFieldSetter { |
||||
s.h.SetShardID(newShardID) |
||||
return s |
||||
// Hash returns the block hash of the header. This uses HeaderRegistry to
|
||||
// choose and return the right tagged RLP form of the header.
|
||||
func (h *Header) Hash() ethcommon.Hash { |
||||
return hash.FromRLP(h) |
||||
} |
||||
|
||||
// LastCommitSignature sets the FBFT commit group signature for the last block.
|
||||
func (s HeaderFieldSetter) LastCommitSignature(newLastCommitSignature [96]byte) HeaderFieldSetter { |
||||
s.h.SetLastCommitSignature(newLastCommitSignature) |
||||
return s |
||||
// Logger returns a sub-logger with block contexts added.
|
||||
func (h *Header) Logger(logger *zerolog.Logger) *zerolog.Logger { |
||||
nlogger := logger.With(). |
||||
Str("blockHash", h.Hash().Hex()). |
||||
Uint32("blockShard", h.ShardID()). |
||||
Uint64("blockEpoch", h.Epoch().Uint64()). |
||||
Uint64("blockNumber", h.Number().Uint64()). |
||||
Logger() |
||||
return &nlogger |
||||
} |
||||
|
||||
// LastCommitBitmap sets the signatory bitmap of the previous block.
|
||||
// With returns a field setter context for the header.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) LastCommitBitmap(newLastCommitBitmap []byte) HeaderFieldSetter { |
||||
s.h.SetLastCommitBitmap(newLastCommitBitmap) |
||||
return s |
||||
} |
||||
|
||||
// ShardStateHash sets the shard state hash.
|
||||
func (s HeaderFieldSetter) ShardStateHash(newShardStateHash common.Hash) HeaderFieldSetter { |
||||
s.h.SetShardStateHash(newShardStateHash) |
||||
return s |
||||
} |
||||
|
||||
// Vrf sets the output of the VRF for the epoch.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) Vrf(newVrf []byte) HeaderFieldSetter { |
||||
s.h.SetVrf(newVrf) |
||||
return s |
||||
} |
||||
|
||||
// Vdf sets the output of the VDF for the epoch.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) Vdf(newVdf []byte) HeaderFieldSetter { |
||||
s.h.SetVdf(newVdf) |
||||
return s |
||||
} |
||||
|
||||
// ShardState sets the RLP-encoded form of shard state
|
||||
// Call a chain of setters on the returned field setter, followed by a call of
|
||||
// Header method. Example:
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) ShardState(newShardState []byte) HeaderFieldSetter { |
||||
s.h.SetShardState(newShardState) |
||||
return s |
||||
// header := NewHeader(epoch).With().
|
||||
// ParentHash(parent.Hash()).
|
||||
// ShardID(parent.ShardID()).
|
||||
// Number(new(big.Int).Add(parent.Number(), big.NewInt(1)).
|
||||
// Header()
|
||||
func (h *Header) With() HeaderFieldSetter { |
||||
return HeaderFieldSetter{h: h} |
||||
} |
||||
|
||||
// CrossLinks sets the RLP-encoded form of non-beacon block headers chosen to be
|
||||
// canonical by the beacon committee.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) CrossLinks(newCrossLinks []byte) HeaderFieldSetter { |
||||
s.h.SetCrossLinks(newCrossLinks) |
||||
return s |
||||
} |
||||
// HeaderRegistry is the taggedrlp type registry for versioned headers.
|
||||
var HeaderRegistry = taggedrlp.NewRegistry() |
||||
|
||||
// Header returns the header whose fields have been set. Call this at the end
|
||||
// of a field setter chain.
|
||||
func (s HeaderFieldSetter) Header() *Header { |
||||
return s.h |
||||
func init() { |
||||
HeaderRegistry.MustRegister(taggedrlp.LegacyTag, v0.NewHeader()) |
||||
HeaderRegistry.MustAddFactory(func() interface{} { return v0.NewHeader() }) |
||||
HeaderRegistry.MustRegister("v1", v1.NewHeader()) |
||||
HeaderRegistry.MustAddFactory(func() interface{} { return v1.NewHeader() }) |
||||
} |
||||
|
@ -0,0 +1,537 @@ |
||||
package block |
||||
|
||||
import ( |
||||
"bytes" |
||||
"reflect" |
||||
"testing" |
||||
|
||||
"github.com/ethereum/go-ethereum/rlp" |
||||
|
||||
v0 "github.com/harmony-one/harmony/block/v0" |
||||
v1 "github.com/harmony-one/harmony/block/v1" |
||||
) |
||||
|
||||
func TestHeader_EncodeRLP(t *testing.T) { |
||||
type fields struct { |
||||
HeaderInterface HeaderInterface |
||||
} |
||||
tests := []struct { |
||||
name string |
||||
fields fields |
||||
want []byte |
||||
wantErr bool |
||||
}{ |
||||
{ |
||||
"v0", |
||||
fields{v0.NewHeader()}, |
||||
[]byte{ |
||||
// BEGIN 586-byte Header
|
||||
0xf9, 0x02, 0x4a, |
||||
0xa0, // 32-byte ParentHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x94, // 20-byte Coinbase
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xa0, // 32-byte Root
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xa0, // 32-byte TxHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xa0, // 32-byte ReceiptHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xb9, 0x01, 0x00, // 256-byte Bloom
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x80, // 0-byte Number
|
||||
0x80, // 0-byte GasLimit
|
||||
0x80, // 0-byte GasUsed
|
||||
0x80, // 0-byte Time
|
||||
0x80, // 0-byte Extra
|
||||
0xa0, // 32-byte MixDigest
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x80, // 0-byte ViewID
|
||||
0x80, // 0-byte Epoch
|
||||
0x80, // 0-byte ShardID
|
||||
0xb8, 0x60, // 96-byte LastCommitSignature
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x80, // 0-byte LastCommitBitmap
|
||||
0xa0, // 32-byte ShardStateHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x80, // 0-byte ShardState
|
||||
// END Header
|
||||
}, |
||||
false, |
||||
}, |
||||
{ |
||||
"v1", |
||||
fields{v1.NewHeader()}, |
||||
[]byte{ |
||||
// BEGIN 669-byte tagged RLP envelope
|
||||
0xf9, 0x02, 0x9d, |
||||
0x87, // 7-byte tagged RLP signature
|
||||
'H', 'm', 'n', 'y', 'T', 'g', 'd', |
||||
0x82, // 2-byte v1 header tag
|
||||
'v', '1', |
||||
// BEGIN 655-byte Header
|
||||
0xf9, 0x02, 0x8f, |
||||
0xa0, // 32-byte ParentHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x94, // 20-byte Coinbase
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xa0, // 32-byte Root
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xa0, // 32-byte TxHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xa0, // 32-byte ReceiptHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xa0, // 32-byte OutgoingReceiptHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xa0, // 32-byte IncomingReceiptHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xb9, 0x01, 0x00, // 256-byte Bloom
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x80, // 0-byte Number
|
||||
0x80, // 0-byte GasLimit
|
||||
0x80, // 0-byte GasUsed
|
||||
0x80, // 0-byte Time
|
||||
0x80, // 0-byte Extra
|
||||
0xa0, // 32-byte MixDigest
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x80, // 0-byte ViewID
|
||||
0x80, // 0-byte Epoch
|
||||
0x80, // 0-byte ShardID
|
||||
0xb8, 0x60, // 96-byte LastCommitSignature
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x80, // 0-byte LastCommitBitmap
|
||||
0xa0, // 32-byte ShardStateHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x80, // 0-byte Vrf
|
||||
0x80, // 0-byte Vdf
|
||||
0x80, // 0-byte ShardState
|
||||
0x80, // 0-byte CrossLinks
|
||||
// END Header
|
||||
// END tagged RLP envelope
|
||||
}, |
||||
false, |
||||
}, |
||||
} |
||||
for _, tt := range tests { |
||||
t.Run(tt.name, func(t *testing.T) { |
||||
h := &Header{HeaderInterface: tt.fields.HeaderInterface} |
||||
w := &bytes.Buffer{} |
||||
err := h.EncodeRLP(w) |
||||
if (err != nil) != tt.wantErr { |
||||
t.Errorf("EncodeRLP() error = %v, wantErr %v", err, tt.wantErr) |
||||
return |
||||
} |
||||
if got := w.Bytes(); bytes.Compare(got, tt.want) != 0 { |
||||
t.Errorf("EncodeRLP() got %x", got) |
||||
t.Errorf("EncodeRLP() want %x", tt.want) |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
|
||||
func TestHeader_DecodeRLP(t *testing.T) { |
||||
type args struct { |
||||
s *rlp.Stream |
||||
} |
||||
tests := []struct { |
||||
name string |
||||
args args |
||||
want HeaderInterface |
||||
wantErr bool |
||||
}{ |
||||
{ |
||||
"v0", |
||||
args{rlp.NewStream(bytes.NewBuffer([]byte{ |
||||
// BEGIN 586-byte Header
|
||||
0xf9, 0x02, 0x4a, |
||||
0xa0, // 32-byte ParentHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x94, // 20-byte Coinbase
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xa0, // 32-byte Root
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xa0, // 32-byte TxHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xa0, // 32-byte ReceiptHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xb9, 0x01, 0x00, // 256-byte Bloom
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x80, // 0-byte Number
|
||||
0x80, // 0-byte GasLimit
|
||||
0x80, // 0-byte GasUsed
|
||||
0x80, // 0-byte Time
|
||||
0x80, // 0-byte Extra
|
||||
0xa0, // 32-byte MixDigest
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x80, // 0-byte ViewID
|
||||
0x80, // 0-byte Epoch
|
||||
0x80, // 0-byte ShardID
|
||||
0xb8, 0x60, // 96-byte LastCommitSignature
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x80, // 0-byte LastCommitBitmap
|
||||
0xa0, // 32-byte ShardStateHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x80, // 0-byte ShardState
|
||||
// END Header
|
||||
}), 0)}, |
||||
v0.NewHeader(), |
||||
false, |
||||
}, |
||||
{ |
||||
"v1", |
||||
args{rlp.NewStream(bytes.NewBuffer([]byte{ |
||||
// BEGIN 669-byte tagged RLP envelope
|
||||
0xf9, 0x02, 0x9d, |
||||
0x87, // 7-byte tagged RLP signature
|
||||
'H', 'm', 'n', 'y', 'T', 'g', 'd', |
||||
0x82, // 2-byte v1 header tag
|
||||
'v', '1', |
||||
// BEGIN 655-byte Header
|
||||
0xf9, 0x02, 0x8f, |
||||
0xa0, // 32-byte ParentHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x94, // 20-byte Coinbase
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xa0, // 32-byte Root
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xa0, // 32-byte TxHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xa0, // 32-byte ReceiptHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xa0, // 32-byte OutgoingReceiptHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xa0, // 32-byte IncomingReceiptHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0xb9, 0x01, 0x00, // 256-byte Bloom
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x80, // 0-byte Number
|
||||
0x80, // 0-byte GasLimit
|
||||
0x80, // 0-byte GasUsed
|
||||
0x80, // 0-byte Time
|
||||
0x80, // 0-byte Extra
|
||||
0xa0, // 32-byte MixDigest
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x80, // 0-byte ViewID
|
||||
0x80, // 0-byte Epoch
|
||||
0x80, // 0-byte ShardID
|
||||
0xb8, 0x60, // 96-byte LastCommitSignature
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x80, // 0-byte LastCommitBitmap
|
||||
0xa0, // 32-byte ShardStateHash
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x80, // 0-byte Vrf
|
||||
0x80, // 0-byte Vdf
|
||||
0x80, // 0-byte ShardState
|
||||
0x80, // 0-byte CrossLinks
|
||||
// END Header
|
||||
// END tagged RLP envelope
|
||||
}), 0)}, |
||||
v1.NewHeader(), |
||||
false, |
||||
}, |
||||
} |
||||
for _, tt := range tests { |
||||
t.Run(tt.name, func(t *testing.T) { |
||||
h := &Header{} |
||||
if err := h.DecodeRLP(tt.args.s); (err != nil) != tt.wantErr { |
||||
t.Errorf("DecodeRLP() error = %v, wantErr %v", err, tt.wantErr) |
||||
} |
||||
if !compareHeaders(h.HeaderInterface, tt.want) { |
||||
t.Errorf("DecodeRLP() got %#v", h.HeaderInterface) |
||||
t.Errorf("DecodeRLP() want %#v", tt.want) |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
|
||||
func equal(x, y interface{}) bool { |
||||
xv := reflect.ValueOf(x) |
||||
yv := reflect.ValueOf(y) |
||||
if xv.Type() == yv.Type() && xv.Type().Kind() == reflect.Slice && xv.Len() == 0 && yv.Len() == 0 { |
||||
return true |
||||
} |
||||
return reflect.DeepEqual(x, y) |
||||
} |
||||
|
||||
func compareHeaders(x, y HeaderInterface) bool { |
||||
return equal(x.ParentHash(), y.ParentHash()) && |
||||
equal(x.Coinbase(), y.Coinbase()) && |
||||
equal(x.Root(), y.Root()) && |
||||
equal(x.TxHash(), y.TxHash()) && |
||||
equal(x.ReceiptHash(), y.ReceiptHash()) && |
||||
equal(x.OutgoingReceiptHash(), y.OutgoingReceiptHash()) && |
||||
equal(x.IncomingReceiptHash(), y.IncomingReceiptHash()) && |
||||
equal(x.Bloom(), y.Bloom()) && |
||||
equal(x.Number(), y.Number()) && |
||||
equal(x.GasLimit(), y.GasLimit()) && |
||||
equal(x.GasUsed(), y.GasUsed()) && |
||||
equal(x.Time(), y.Time()) && |
||||
equal(x.Extra(), y.Extra()) && |
||||
equal(x.MixDigest(), y.MixDigest()) && |
||||
equal(x.ViewID(), y.ViewID()) && |
||||
equal(x.Epoch(), y.Epoch()) && |
||||
equal(x.ShardID(), y.ShardID()) && |
||||
equal(x.LastCommitSignature(), y.LastCommitSignature()) && |
||||
equal(x.LastCommitBitmap(), y.LastCommitBitmap()) && |
||||
equal(x.ShardStateHash(), y.ShardStateHash()) && |
||||
equal(x.Vrf(), y.Vrf()) && |
||||
equal(x.Vdf(), y.Vdf()) && |
||||
equal(x.ShardState(), y.ShardState()) && |
||||
equal(x.CrossLinks(), y.CrossLinks()) |
||||
} |
@ -0,0 +1,186 @@ |
||||
package block |
||||
|
||||
import ( |
||||
"math/big" |
||||
|
||||
"github.com/ethereum/go-ethereum/common" |
||||
"github.com/ethereum/go-ethereum/core/types" |
||||
) |
||||
|
||||
// HeaderFieldSetter is a header field setter.
|
||||
//
|
||||
// See NewHeaderWith for how it is used.
|
||||
type HeaderFieldSetter struct { |
||||
h *Header |
||||
} |
||||
|
||||
// ParentHash sets the parent hash field.
|
||||
func (s HeaderFieldSetter) ParentHash(newParentHash common.Hash) HeaderFieldSetter { |
||||
s.h.SetParentHash(newParentHash) |
||||
return s |
||||
} |
||||
|
||||
// Coinbase sets the coinbase address field.
|
||||
func (s HeaderFieldSetter) Coinbase(newCoinbase common.Address) HeaderFieldSetter { |
||||
s.h.SetCoinbase(newCoinbase) |
||||
return s |
||||
} |
||||
|
||||
// Root sets the state trie root hash field.
|
||||
func (s HeaderFieldSetter) Root(newRoot common.Hash) HeaderFieldSetter { |
||||
s.h.SetRoot(newRoot) |
||||
return s |
||||
} |
||||
|
||||
// TxHash sets the transaction trie root hash field.
|
||||
func (s HeaderFieldSetter) TxHash(newTxHash common.Hash) HeaderFieldSetter { |
||||
s.h.SetTxHash(newTxHash) |
||||
return s |
||||
} |
||||
|
||||
// ReceiptHash sets the same-shard transaction receipt trie hash.
|
||||
func (s HeaderFieldSetter) ReceiptHash(newReceiptHash common.Hash) HeaderFieldSetter { |
||||
s.h.SetReceiptHash(newReceiptHash) |
||||
return s |
||||
} |
||||
|
||||
// OutgoingReceiptHash sets the egress transaction receipt trie hash.
|
||||
func (s HeaderFieldSetter) OutgoingReceiptHash(newOutgoingReceiptHash common.Hash) HeaderFieldSetter { |
||||
s.h.SetOutgoingReceiptHash(newOutgoingReceiptHash) |
||||
return s |
||||
} |
||||
|
||||
// IncomingReceiptHash sets the ingress transaction receipt trie hash.
|
||||
func (s HeaderFieldSetter) IncomingReceiptHash(newIncomingReceiptHash common.Hash) HeaderFieldSetter { |
||||
s.h.SetIncomingReceiptHash(newIncomingReceiptHash) |
||||
return s |
||||
} |
||||
|
||||
// Bloom sets the smart contract log Bloom filter for this block.
|
||||
func (s HeaderFieldSetter) Bloom(newBloom types.Bloom) HeaderFieldSetter { |
||||
s.h.SetBloom(newBloom) |
||||
return s |
||||
} |
||||
|
||||
// Number sets the block number.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) Number(newNumber *big.Int) HeaderFieldSetter { |
||||
s.h.SetNumber(newNumber) |
||||
return s |
||||
} |
||||
|
||||
// GasLimit sets the gas limit for transactions in this block.
|
||||
func (s HeaderFieldSetter) GasLimit(newGasLimit uint64) HeaderFieldSetter { |
||||
s.h.SetGasLimit(newGasLimit) |
||||
return s |
||||
} |
||||
|
||||
// GasUsed sets the amount of gas used by transactions in this block.
|
||||
func (s HeaderFieldSetter) GasUsed(newGasUsed uint64) HeaderFieldSetter { |
||||
s.h.SetGasUsed(newGasUsed) |
||||
return s |
||||
} |
||||
|
||||
// Time sets the UNIX timestamp of this block.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) Time(newTime *big.Int) HeaderFieldSetter { |
||||
s.h.SetTime(newTime) |
||||
return s |
||||
} |
||||
|
||||
// Extra sets the extra data field of this block.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) Extra(newExtra []byte) HeaderFieldSetter { |
||||
s.h.SetExtra(newExtra) |
||||
return s |
||||
} |
||||
|
||||
// MixDigest sets the mixhash of this block.
|
||||
func (s HeaderFieldSetter) MixDigest(newMixDigest common.Hash) HeaderFieldSetter { |
||||
s.h.SetMixDigest(newMixDigest) |
||||
return s |
||||
} |
||||
|
||||
// ViewID sets the view ID in which the block was originally proposed.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) ViewID(newViewID *big.Int) HeaderFieldSetter { |
||||
s.h.SetViewID(newViewID) |
||||
return s |
||||
} |
||||
|
||||
// Epoch sets the epoch number of this block.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) Epoch(newEpoch *big.Int) HeaderFieldSetter { |
||||
s.h.SetEpoch(newEpoch) |
||||
return s |
||||
} |
||||
|
||||
// ShardID sets the shard ID to which this block belongs.
|
||||
func (s HeaderFieldSetter) ShardID(newShardID uint32) HeaderFieldSetter { |
||||
s.h.SetShardID(newShardID) |
||||
return s |
||||
} |
||||
|
||||
// LastCommitSignature sets the FBFT commit group signature for the last block.
|
||||
func (s HeaderFieldSetter) LastCommitSignature(newLastCommitSignature [96]byte) HeaderFieldSetter { |
||||
s.h.SetLastCommitSignature(newLastCommitSignature) |
||||
return s |
||||
} |
||||
|
||||
// LastCommitBitmap sets the signatory bitmap of the previous block.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) LastCommitBitmap(newLastCommitBitmap []byte) HeaderFieldSetter { |
||||
s.h.SetLastCommitBitmap(newLastCommitBitmap) |
||||
return s |
||||
} |
||||
|
||||
// ShardStateHash sets the shard state hash.
|
||||
func (s HeaderFieldSetter) ShardStateHash(newShardStateHash common.Hash) HeaderFieldSetter { |
||||
s.h.SetShardStateHash(newShardStateHash) |
||||
return s |
||||
} |
||||
|
||||
// Vrf sets the output of the VRF for the epoch.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) Vrf(newVrf []byte) HeaderFieldSetter { |
||||
s.h.SetVrf(newVrf) |
||||
return s |
||||
} |
||||
|
||||
// Vdf sets the output of the VDF for the epoch.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) Vdf(newVdf []byte) HeaderFieldSetter { |
||||
s.h.SetVdf(newVdf) |
||||
return s |
||||
} |
||||
|
||||
// ShardState sets the RLP-encoded form of shard state
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) ShardState(newShardState []byte) HeaderFieldSetter { |
||||
s.h.SetShardState(newShardState) |
||||
return s |
||||
} |
||||
|
||||
// CrossLinks sets the RLP-encoded form of non-beacon block headers chosen to be
|
||||
// canonical by the beacon committee.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
func (s HeaderFieldSetter) CrossLinks(newCrossLinks []byte) HeaderFieldSetter { |
||||
s.h.SetCrossLinks(newCrossLinks) |
||||
return s |
||||
} |
||||
|
||||
// Header returns the header whose fields have been set. Call this at the end
|
||||
// of a field setter chain.
|
||||
func (s HeaderFieldSetter) Header() *Header { |
||||
return s.h |
||||
} |
@ -0,0 +1,228 @@ |
||||
package block |
||||
|
||||
import ( |
||||
"math/big" |
||||
|
||||
"github.com/ethereum/go-ethereum/common" |
||||
"github.com/ethereum/go-ethereum/core/types" |
||||
"github.com/rs/zerolog" |
||||
|
||||
"github.com/harmony-one/harmony/shard" |
||||
) |
||||
|
||||
// HeaderInterface defines the block header interface.
|
||||
type HeaderInterface interface { |
||||
// ParentHash is the header hash of the parent block. For the genesis block
|
||||
// which has no parent by definition, this field is zeroed out.
|
||||
ParentHash() common.Hash |
||||
|
||||
// SetParentHash sets the parent hash field.
|
||||
SetParentHash(newParentHash common.Hash) |
||||
|
||||
// Coinbase is the address of the node that proposed this block and all
|
||||
// transactions in it.
|
||||
Coinbase() common.Address |
||||
|
||||
// SetCoinbase sets the coinbase address field.
|
||||
SetCoinbase(newCoinbase common.Address) |
||||
|
||||
// Root is the state (account) trie root hash.
|
||||
Root() common.Hash |
||||
|
||||
// SetRoot sets the state trie root hash field.
|
||||
SetRoot(newRoot common.Hash) |
||||
|
||||
// TxHash is the transaction trie root hash.
|
||||
TxHash() common.Hash |
||||
|
||||
// SetTxHash sets the transaction trie root hash field.
|
||||
SetTxHash(newTxHash common.Hash) |
||||
|
||||
// ReceiptHash is the same-shard transaction receipt trie hash.
|
||||
ReceiptHash() common.Hash |
||||
|
||||
// SetReceiptHash sets the same-shard transaction receipt trie hash.
|
||||
SetReceiptHash(newReceiptHash common.Hash) |
||||
|
||||
// OutgoingReceiptHash is the egress transaction receipt trie hash.
|
||||
OutgoingReceiptHash() common.Hash |
||||
|
||||
// SetOutgoingReceiptHash sets the egress transaction receipt trie hash.
|
||||
SetOutgoingReceiptHash(newOutgoingReceiptHash common.Hash) |
||||
|
||||
// IncomingReceiptHash is the ingress transaction receipt trie hash.
|
||||
IncomingReceiptHash() common.Hash |
||||
|
||||
// SetIncomingReceiptHash sets the ingress transaction receipt trie hash.
|
||||
SetIncomingReceiptHash(newIncomingReceiptHash common.Hash) |
||||
|
||||
// Bloom is the Bloom filter that indexes accounts and topics logged by smart
|
||||
// contract transactions (executions) in this block.
|
||||
Bloom() types.Bloom |
||||
|
||||
// SetBloom sets the smart contract log Bloom filter for this block.
|
||||
SetBloom(newBloom types.Bloom) |
||||
|
||||
// Number is the block number.
|
||||
//
|
||||
// The returned instance is a copy; the caller may do anything with it.
|
||||
Number() *big.Int |
||||
|
||||
// SetNumber sets the block number.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
SetNumber(newNumber *big.Int) |
||||
|
||||
// GasLimit is the gas limit for transactions in this block.
|
||||
GasLimit() uint64 |
||||
|
||||
// SetGasLimit sets the gas limit for transactions in this block.
|
||||
SetGasLimit(newGasLimit uint64) |
||||
|
||||
// GasUsed is the amount of gas used by transactions in this block.
|
||||
GasUsed() uint64 |
||||
|
||||
// SetGasUsed sets the amount of gas used by transactions in this block.
|
||||
SetGasUsed(newGasUsed uint64) |
||||
|
||||
// Time is the UNIX timestamp of this block.
|
||||
//
|
||||
// The returned instance is a copy; the caller may do anything with it.
|
||||
Time() *big.Int |
||||
|
||||
// SetTime sets the UNIX timestamp of this block.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
SetTime(newTime *big.Int) |
||||
|
||||
// Extra is the extra data field of this block.
|
||||
//
|
||||
// The returned slice is a copy; the caller may do anything with it.
|
||||
Extra() []byte |
||||
|
||||
// SetExtra sets the extra data field of this block.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
SetExtra(newExtra []byte) |
||||
|
||||
// MixDigest is the mixhash.
|
||||
//
|
||||
// This field is a remnant from Ethereum, and Harmony does not use it and always
|
||||
// zeroes it out.
|
||||
MixDigest() common.Hash |
||||
|
||||
// SetMixDigest sets the mixhash of this block.
|
||||
SetMixDigest(newMixDigest common.Hash) |
||||
|
||||
// ViewID is the ID of the view in which this block was originally proposed.
|
||||
//
|
||||
// It normally increases by one for each subsequent block, or by more than one
|
||||
// if one or more PBFT/FBFT view changes have occurred.
|
||||
//
|
||||
// The returned instance is a copy; the caller may do anything with it.
|
||||
ViewID() *big.Int |
||||
|
||||
// SetViewID sets the view ID in which the block was originally proposed.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
SetViewID(newViewID *big.Int) |
||||
|
||||
// Epoch is the epoch number of this block.
|
||||
//
|
||||
// The returned instance is a copy; the caller may do anything with it.
|
||||
Epoch() *big.Int |
||||
|
||||
// SetEpoch sets the epoch number of this block.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
SetEpoch(newEpoch *big.Int) |
||||
|
||||
// ShardID is the shard ID to which this block belongs.
|
||||
ShardID() uint32 |
||||
|
||||
// SetShardID sets the shard ID to which this block belongs.
|
||||
SetShardID(newShardID uint32) |
||||
|
||||
// LastCommitSignature is the FBFT commit group signature for the last block.
|
||||
LastCommitSignature() [96]byte |
||||
|
||||
// SetLastCommitSignature sets the FBFT commit group signature for the last
|
||||
// block.
|
||||
SetLastCommitSignature(newLastCommitSignature [96]byte) |
||||
|
||||
// LastCommitBitmap is the signatory bitmap of the previous block. Bit
|
||||
// positions index into committee member array.
|
||||
//
|
||||
// The returned slice is a copy; the caller may do anything with it.
|
||||
LastCommitBitmap() []byte |
||||
|
||||
// SetLastCommitBitmap sets the signatory bitmap of the previous block.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
SetLastCommitBitmap(newLastCommitBitmap []byte) |
||||
|
||||
// ShardStateHash is the shard state hash.
|
||||
ShardStateHash() common.Hash |
||||
|
||||
// SetShardStateHash sets the shard state hash.
|
||||
SetShardStateHash(newShardStateHash common.Hash) |
||||
|
||||
// Vrf is the output of the VRF for the epoch.
|
||||
//
|
||||
// The returned slice is a copy; the caller may do anything with it.
|
||||
Vrf() []byte |
||||
|
||||
// SetVrf sets the output of the VRF for the epoch.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
SetVrf(newVrf []byte) |
||||
|
||||
// Vdf is the output of the VDF for the epoch.
|
||||
//
|
||||
// The returned slice is a copy; the caller may do anything with it.
|
||||
Vdf() []byte |
||||
|
||||
// SetVdf sets the output of the VDF for the epoch.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
SetVdf(newVdf []byte) |
||||
|
||||
// ShardState is the RLP-encoded form of shard state (list of committees) for
|
||||
// the next epoch.
|
||||
//
|
||||
// The returned slice is a copy; the caller may do anything with it.
|
||||
ShardState() []byte |
||||
|
||||
// SetShardState sets the RLP-encoded form of shard state
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
SetShardState(newShardState []byte) |
||||
|
||||
// CrossLinks is the RLP-encoded form of non-beacon block headers chosen to be
|
||||
// canonical by the beacon committee. This field is present only on beacon
|
||||
// chain block headers.
|
||||
//
|
||||
// The returned slice is a copy; the caller may do anything with it.
|
||||
CrossLinks() []byte |
||||
|
||||
// SetCrossLinks sets the RLP-encoded form of non-beacon block headers chosen to
|
||||
// be canonical by the beacon committee.
|
||||
//
|
||||
// It stores a copy; the caller may freely modify the original.
|
||||
SetCrossLinks(newCrossLinks []byte) |
||||
|
||||
// Hash returns the block hash of the header, which is simply the legacy
|
||||
// Keccak256 hash of its RLP encoding.
|
||||
Hash() common.Hash |
||||
|
||||
// Size returns the approximate memory used by all internal contents. It is
|
||||
// used to approximate and limit the memory consumption of various caches.
|
||||
Size() common.StorageSize |
||||
|
||||
// Logger returns a sub-logger with block contexts added.
|
||||
Logger(logger *zerolog.Logger) *zerolog.Logger |
||||
|
||||
// GetShardState returns the deserialized shard state object.
|
||||
GetShardState() (shard.State, error) |
||||
} |
||||
|
Loading…
Reference in new issue