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

Mmr hardfork #4198

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions block/factory/factory.go
Expand Up @@ -9,6 +9,7 @@ import (
v1 "github.com/harmony-one/harmony/block/v1"
v2 "github.com/harmony-one/harmony/block/v2"
v3 "github.com/harmony-one/harmony/block/v3"
v4 "github.com/harmony-one/harmony/block/v4"
"github.com/harmony-one/harmony/internal/params"
)

Expand All @@ -30,6 +31,8 @@ func NewFactory(chainConfig *params.ChainConfig) Factory {
func (f *factory) NewHeader(epoch *big.Int) *block.Header {
var impl blockif.Header
switch {
case f.chainConfig.IsMMRHeaderEpoch(epoch):
impl = v4.NewHeader()
case f.chainConfig.IsPreStaking(epoch) || f.chainConfig.IsStaking(epoch):
impl = v3.NewHeader()
case f.chainConfig.IsCrossLink(epoch):
Expand Down
3 changes: 3 additions & 0 deletions block/header.go
Expand Up @@ -15,6 +15,7 @@ import (
v1 "github.com/harmony-one/harmony/block/v1"
v2 "github.com/harmony-one/harmony/block/v2"
v3 "github.com/harmony-one/harmony/block/v3"
v4 "github.com/harmony-one/harmony/block/v4"
"github.com/harmony-one/harmony/crypto/hash"
"github.com/harmony-one/taggedrlp"
"github.com/pkg/errors"
Expand Down Expand Up @@ -165,4 +166,6 @@ func init() {
HeaderRegistry.MustAddFactory(func() interface{} { return v2.NewHeader() })
HeaderRegistry.MustRegister("v3", v3.NewHeader())
HeaderRegistry.MustAddFactory(func() interface{} { return v3.NewHeader() })
HeaderRegistry.MustRegister("v4", v4.NewHeader())
HeaderRegistry.MustAddFactory(func() interface{} { return v4.NewHeader() })
}
7 changes: 7 additions & 0 deletions block/interface/header.go
Expand Up @@ -236,4 +236,11 @@ type Header interface {
// SetSlashes sets the RLP-encoded form of slashes
// It stores a copy; the caller may freely modify the original.
SetSlashes(newSlashes []byte)

// MMRRoot is the root of the Merkle Mountain Range tree formed
// using the block hashes of the current epoch
MMRRoot() common.Hash

// SetMMRRoot sets the updated MMR root after appending the parentHash
SetMMRRoot(newMMRRoot common.Hash)
}
15 changes: 15 additions & 0 deletions block/v0/header.go
Expand Up @@ -395,6 +395,21 @@ func (h *Header) SetSlashes(newSlashes []byte) {
Msg("cannot store slashes in V0 header")
}

// MMRRoot is the root of the Merkle Mountain Range tree formed
// using the block hashes of the current epoch
func (h *Header) MMRRoot() common.Hash {
h.Logger(utils.Logger()).Error().
Msg("No MMRRoot in V0 header")
return common.Hash{}
}

// SetMMRRoot sets the updated MMR root after appending the parentHash
func (h *Header) SetMMRRoot(newMMRRoot common.Hash) {
h.Logger(utils.Logger()).Error().
Hex("mmrRoot", newMMRRoot[:]).
Msg("cannot store mmrRoot in V0 header")
}

// field type overrides for gencodec
type headerMarshaling struct {
Difficulty *hexutil.Big
Expand Down
15 changes: 15 additions & 0 deletions block/v1/header.go
Expand Up @@ -379,6 +379,21 @@ func (h *Header) SetSlashes(newSlashes []byte) {
Msg("cannot store slashes in V1 header")
}

// MMRRoot is the root of the Merkle Mountain Range tree formed
// using the block hashes of the current epoch
func (h *Header) MMRRoot() common.Hash {
h.Logger(utils.Logger()).Error().
Msg("No MMRRoot in V1 header")
return common.Hash{}
}

// SetMMRRoot sets the updated MMR root after appending the parentHash
func (h *Header) SetMMRRoot(newMMRRoot common.Hash) {
h.Logger(utils.Logger()).Error().
Hex("mmrRoot", newMMRRoot[:]).
Msg("cannot store mmrRoot in V1 header")
}

// field type overrides for gencodec
type headerMarshaling struct {
Difficulty *hexutil.Big
Expand Down
15 changes: 15 additions & 0 deletions block/v2/header.go
Expand Up @@ -378,6 +378,21 @@ func (h *Header) SetSlashes(newSlashes []byte) {
Msg("cannot store slashes in V2 header")
}

// MMRRoot is the root of the Merkle Mountain Range tree formed
// using the block hashes of the current epoch
func (h *Header) MMRRoot() common.Hash {
h.Logger(utils.Logger()).Error().
Msg("No MMRRoot in V2 header")
return common.Hash{}
}

// SetMMRRoot sets the updated MMR root after appending the parentHash
func (h *Header) SetMMRRoot(newMMRRoot common.Hash) {
h.Logger(utils.Logger()).Error().
Hex("mmrRoot", newMMRRoot[:]).
Msg("cannot store mmrRoot in V2 header")
}

// field type overrides for gencodec
type headerMarshaling struct {
Difficulty *hexutil.Big
Expand Down
15 changes: 15 additions & 0 deletions block/v3/header.go
Expand Up @@ -380,6 +380,21 @@ func (h *Header) SetSlashes(newSlashes []byte) {
h.fields.Slashes = append(newSlashes[:0:0], newSlashes...)
}

// MMRRoot is the root of the Merkle Mountain Range tree formed
// using the block hashes of the current epoch
func (h *Header) MMRRoot() common.Hash {
h.Logger(utils.Logger()).Error().
Msg("No MMRRoot in V3 header")
return common.Hash{}
}

// SetMMRRoot sets the updated MMR root after appending the parentHash
func (h *Header) SetMMRRoot(newMMRRoot common.Hash) {
h.Logger(utils.Logger()).Error().
Hex("mmrRoot", newMMRRoot[:]).
Msg("cannot store mmrRoot in V3 header")
}

// Hash returns the block hash of the header, which is simply the keccak256 hash of its
// RLP encoding.
func (h *Header) Hash() common.Hash {
Expand Down