mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 10:12:19 +00:00
d1aa843ea6
Former-commit-id: 5febe72a5a1936ce643488067e0990da810f1f5e [formerly 74c85fc99b259d064b5181f91cddf945e3d7b988] Former-commit-id: 0cc6d451b5eee6e459597ad114a85bacc7a953f1
65 lines
2.2 KiB
Go
65 lines
2.2 KiB
Go
package sharding
|
|
|
|
import (
|
|
"math/big"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
"github.com/ethereum/go-ethereum/crypto/sha3"
|
|
"github.com/ethereum/go-ethereum/rlp"
|
|
)
|
|
|
|
// Collation base struct.
|
|
type Collation struct {
|
|
header *CollationHeader
|
|
body []byte
|
|
transactions []*types.Transaction
|
|
}
|
|
|
|
// CollationHeader base struct.
|
|
type CollationHeader struct {
|
|
shardID *big.Int //the shard ID of the shard.
|
|
chunkRoot *common.Hash //the root of the chunk tree which identifies collation body.
|
|
period *big.Int //the period number in which collation to be included.
|
|
proposerAddress *common.Address //address of the collation proposer.
|
|
proposerSignature []byte //the proposer's signature for calculating collation hash.
|
|
}
|
|
|
|
// Hash takes the keccak256 of the collation header's contents.
|
|
func (h *CollationHeader) Hash() (hash common.Hash) {
|
|
hw := sha3.NewKeccak256()
|
|
rlp.Encode(hw, h)
|
|
hw.Sum(hash[:0])
|
|
return hash
|
|
}
|
|
|
|
// ShardID is the identifier for a shard.
|
|
func (h *CollationHeader) ShardID() *big.Int { return h.shardID }
|
|
|
|
// Period the collation corresponds to.
|
|
func (h *CollationHeader) Period() *big.Int { return h.period }
|
|
|
|
// ChunkRoot of the serialized collation body.
|
|
func (h *CollationHeader) ChunkRoot() *common.Hash { return h.chunkRoot }
|
|
|
|
// Header returns the collation's header.
|
|
func (c *Collation) Header() *CollationHeader { return c.header }
|
|
|
|
// Body returns the collation's byte body.
|
|
func (c *Collation) Body() []byte { return c.body }
|
|
|
|
// Transactions returns an array of tx's in the collation.
|
|
func (c *Collation) Transactions() []*types.Transaction { return c.transactions }
|
|
|
|
// ProposerAddress is the coinbase addr of the creator for the collation.
|
|
func (c *Collation) ProposerAddress() *common.Address { return c.header.proposerAddress }
|
|
|
|
// SetHeader updates the collation's header.
|
|
func (c *Collation) SetHeader(h *CollationHeader) { c.header = h }
|
|
|
|
// AddTransaction adds to the collation's body of tx blobs.
|
|
func (c *Collation) AddTransaction(tx *types.Transaction) {
|
|
// TODO: Include blob serialization instead.
|
|
c.transactions = append(c.transactions, tx)
|
|
}
|