mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
ADDED LCP engine
This commit is contained in:
parent
ad0b74b4ea
commit
103d3f45f8
1 changed files with 171 additions and 54 deletions
|
|
@ -5,11 +5,11 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/meitu/go-ethereum/common"
|
"github.com/pavelkrolevets/go-ethereum/common"
|
||||||
"github.com/meitu/go-ethereum/crypto/sha3"
|
"github.com/pavelkrolevets/go-ethereum/crypto/sha3"
|
||||||
"github.com/meitu/go-ethereum/ethdb"
|
"github.com/pavelkrolevets/go-ethereum/rlp"
|
||||||
"github.com/meitu/go-ethereum/rlp"
|
"github.com/pavelkrolevets/go-ethereum/trie"
|
||||||
"github.com/meitu/go-ethereum/trie"
|
"encoding/binary"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LCPContext struct {
|
type LCPContext struct {
|
||||||
|
|
@ -18,11 +18,11 @@ type LCPContext struct {
|
||||||
voteTrie *trie.Trie
|
voteTrie *trie.Trie
|
||||||
candidateTrie *trie.Trie
|
candidateTrie *trie.Trie
|
||||||
mintCntTrie *trie.Trie
|
mintCntTrie *trie.Trie
|
||||||
period uint64
|
periodBlock *trie.Trie
|
||||||
maxValidators uint64
|
maxValidators *trie.Trie
|
||||||
epochInterval uint64
|
epochInterval *trie.Trie
|
||||||
|
|
||||||
db ethdb.Database
|
db *trie.Database
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -31,29 +31,42 @@ var (
|
||||||
votePrefix = []byte("vote-")
|
votePrefix = []byte("vote-")
|
||||||
candidatePrefix = []byte("candidate-")
|
candidatePrefix = []byte("candidate-")
|
||||||
mintCntPrefix = []byte("mintCnt-")
|
mintCntPrefix = []byte("mintCnt-")
|
||||||
|
periodBlockPrefix = []byte("Period-")
|
||||||
|
maxValidatorsPrefix = []byte("MaxValidator-")
|
||||||
|
epochIntervalPrefix = []byte("EpochInterval-")
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewEpochTrie(root common.Hash, db ethdb.Database) (*trie.Trie, error) {
|
func NewEpochTrie(root common.Hash, db *trie.Database) (*trie.Trie, error) {
|
||||||
return trie.NewTrieWithPrefix(root, epochPrefix, db)
|
return trie.NewTrieWithPrefix(root, epochPrefix, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDelegateTrie(root common.Hash, db ethdb.Database) (*trie.Trie, error) {
|
func NewDelegateTrie(root common.Hash, db *trie.Database) (*trie.Trie, error) {
|
||||||
return trie.NewTrieWithPrefix(root, delegatePrefix, db)
|
return trie.NewTrieWithPrefix(root, delegatePrefix, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVoteTrie(root common.Hash, db ethdb.Database) (*trie.Trie, error) {
|
func NewVoteTrie(root common.Hash, db *trie.Database) (*trie.Trie, error) {
|
||||||
return trie.NewTrieWithPrefix(root, votePrefix, db)
|
return trie.NewTrieWithPrefix(root, votePrefix, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCandidateTrie(root common.Hash, db ethdb.Database) (*trie.Trie, error) {
|
func NewCandidateTrie(root common.Hash, db *trie.Database) (*trie.Trie, error) {
|
||||||
return trie.NewTrieWithPrefix(root, candidatePrefix, db)
|
return trie.NewTrieWithPrefix(root, candidatePrefix, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMintCntTrie(root common.Hash, db ethdb.Database) (*trie.Trie, error) {
|
func NewMintCntTrie(root common.Hash, db *trie.Database) (*trie.Trie, error) {
|
||||||
return trie.NewTrieWithPrefix(root, mintCntPrefix, db)
|
return trie.NewTrieWithPrefix(root, mintCntPrefix, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLCPContext(db ethdb.Database) (*LCPContext, error) {
|
func NewPeriodBlockTrie(root common.Hash, db *trie.Database) (*trie.Trie, error) {
|
||||||
|
return trie.NewTrieWithPrefix(root, periodBlockPrefix, db)
|
||||||
|
}
|
||||||
|
func NewMaxValidatorsTrie(root common.Hash, db *trie.Database) (*trie.Trie, error) {
|
||||||
|
return trie.NewTrieWithPrefix(root, maxValidatorsPrefix, db)
|
||||||
|
}
|
||||||
|
func NewEpochIntervalTrie(root common.Hash, db *trie.Database) (*trie.Trie, error) {
|
||||||
|
return trie.NewTrieWithPrefix(root, epochIntervalPrefix, db)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLCPContext(db *trie.Database) (*LCPContext, error) {
|
||||||
epochTrie, err := NewEpochTrie(common.Hash{}, db)
|
epochTrie, err := NewEpochTrie(common.Hash{}, db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -75,17 +88,32 @@ func NewLCPContext(db ethdb.Database) (*LCPContext, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
periodTrie, err := NewPeriodBlockTrie(common.Hash{}, db)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
maxValidatorTrie, err := NewMaxValidatorsTrie(common.Hash{}, db)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
epochIntervalTrie, err := NewEpochIntervalTrie(common.Hash{}, db)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return &LCPContext{
|
return &LCPContext{
|
||||||
epochTrie: epochTrie,
|
epochTrie: epochTrie,
|
||||||
delegateTrie: delegateTrie,
|
delegateTrie: delegateTrie,
|
||||||
voteTrie: voteTrie,
|
voteTrie: voteTrie,
|
||||||
candidateTrie: candidateTrie,
|
candidateTrie: candidateTrie,
|
||||||
mintCntTrie: mintCntTrie,
|
mintCntTrie: mintCntTrie,
|
||||||
|
periodBlock: periodTrie,
|
||||||
|
maxValidators: maxValidatorTrie,
|
||||||
|
epochInterval: epochIntervalTrie,
|
||||||
db: db,
|
db: db,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLCPContextFromProto(db ethdb.Database, ctxProto *LCPContextProto) (*LCPContext, error) {
|
func NewLCPContextFromProto(db *trie.Database, ctxProto *LCPContextProto) (*LCPContext, error) {
|
||||||
epochTrie, err := NewEpochTrie(ctxProto.EpochHash, db)
|
epochTrie, err := NewEpochTrie(ctxProto.EpochHash, db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -106,12 +134,27 @@ func NewLCPContextFromProto(db ethdb.Database, ctxProto *LCPContextProto) (*LCPC
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
periodTrie, err := NewPeriodBlockTrie(common.Hash{}, db)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
maxValidatorTrie, err := NewMaxValidatorsTrie(common.Hash{}, db)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
epochIntervalTrie, err := NewEpochIntervalTrie(common.Hash{}, db)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return &LCPContext{
|
return &LCPContext{
|
||||||
epochTrie: epochTrie,
|
epochTrie: epochTrie,
|
||||||
delegateTrie: delegateTrie,
|
delegateTrie: delegateTrie,
|
||||||
voteTrie: voteTrie,
|
voteTrie: voteTrie,
|
||||||
candidateTrie: candidateTrie,
|
candidateTrie: candidateTrie,
|
||||||
mintCntTrie: mintCntTrie,
|
mintCntTrie: mintCntTrie,
|
||||||
|
periodBlock: periodTrie,
|
||||||
|
maxValidators: maxValidatorTrie,
|
||||||
|
epochInterval: epochIntervalTrie,
|
||||||
db: db,
|
db: db,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
@ -122,12 +165,18 @@ func (d *LCPContext) Copy() *LCPContext {
|
||||||
voteTrie := *d.voteTrie
|
voteTrie := *d.voteTrie
|
||||||
candidateTrie := *d.candidateTrie
|
candidateTrie := *d.candidateTrie
|
||||||
mintCntTrie := *d.mintCntTrie
|
mintCntTrie := *d.mintCntTrie
|
||||||
|
periodTrie:= *d.periodBlock
|
||||||
|
maxValidatorTrie:= *d.maxValidators
|
||||||
|
epochIntervalTrie:= *d.epochInterval
|
||||||
return &LCPContext{
|
return &LCPContext{
|
||||||
epochTrie: &epochTrie,
|
epochTrie: &epochTrie,
|
||||||
delegateTrie: &delegateTrie,
|
delegateTrie: &delegateTrie,
|
||||||
voteTrie: &voteTrie,
|
voteTrie: &voteTrie,
|
||||||
candidateTrie: &candidateTrie,
|
candidateTrie: &candidateTrie,
|
||||||
mintCntTrie: &mintCntTrie,
|
mintCntTrie: &mintCntTrie,
|
||||||
|
periodBlock: &periodTrie,
|
||||||
|
maxValidators: &maxValidatorTrie,
|
||||||
|
epochInterval: &epochIntervalTrie,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -138,7 +187,9 @@ func (d *LCPContext) Root() (h common.Hash) {
|
||||||
rlp.Encode(hw, d.candidateTrie.Hash())
|
rlp.Encode(hw, d.candidateTrie.Hash())
|
||||||
rlp.Encode(hw, d.voteTrie.Hash())
|
rlp.Encode(hw, d.voteTrie.Hash())
|
||||||
rlp.Encode(hw, d.mintCntTrie.Hash())
|
rlp.Encode(hw, d.mintCntTrie.Hash())
|
||||||
|
rlp.Encode(hw, d.periodBlock.Hash())
|
||||||
|
rlp.Encode(hw, d.maxValidators.Hash())
|
||||||
|
rlp.Encode(hw, d.epochInterval.Hash())
|
||||||
hw.Sum(h[:0])
|
hw.Sum(h[:0])
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
@ -153,6 +204,9 @@ func (d *LCPContext) RevertToSnapShot(snapshot *LCPContext) {
|
||||||
d.candidateTrie = snapshot.candidateTrie
|
d.candidateTrie = snapshot.candidateTrie
|
||||||
d.voteTrie = snapshot.voteTrie
|
d.voteTrie = snapshot.voteTrie
|
||||||
d.mintCntTrie = snapshot.mintCntTrie
|
d.mintCntTrie = snapshot.mintCntTrie
|
||||||
|
d.periodBlock = snapshot.periodBlock
|
||||||
|
d.maxValidators = snapshot.maxValidators
|
||||||
|
d.epochInterval = snapshot.epochInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *LCPContext) FromProto(dcp *LCPContextProto) error {
|
func (d *LCPContext) FromProto(dcp *LCPContextProto) error {
|
||||||
|
|
@ -174,10 +228,21 @@ func (d *LCPContext) FromProto(dcp *LCPContextProto) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
d.mintCntTrie, err = NewMintCntTrie(dcp.MintCntHash, d.db)
|
d.mintCntTrie, err = NewMintCntTrie(dcp.MintCntHash, d.db)
|
||||||
|
if err != nil {
|
||||||
d.period = dcp.period
|
return err
|
||||||
d.epochInterval = dcp.epochInterval
|
}
|
||||||
d.maxValidators = dcp.maxValidators
|
d.periodBlock, err = NewPeriodBlockTrie(dcp.periodBlockHash, d.db)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
d.maxValidators, err = NewPeriodBlockTrie(dcp.maxValidatorsHash, d.db)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
d.epochInterval, err = NewPeriodBlockTrie(dcp.epochIntervalHash, d.db)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -187,9 +252,9 @@ type LCPContextProto struct {
|
||||||
CandidateHash common.Hash `json:"candidateRoot" gencodec:"required"`
|
CandidateHash common.Hash `json:"candidateRoot" gencodec:"required"`
|
||||||
VoteHash common.Hash `json:"voteRoot" gencodec:"required"`
|
VoteHash common.Hash `json:"voteRoot" gencodec:"required"`
|
||||||
MintCntHash common.Hash `json:"mintCntRoot" gencodec:"required"`
|
MintCntHash common.Hash `json:"mintCntRoot" gencodec:"required"`
|
||||||
period uint64
|
periodBlockHash common.Hash `json:"periodBlockRoot" gencodec:"required"`
|
||||||
maxValidators uint64
|
maxValidatorsHash common.Hash `json:"maxValidatorRoot" gencodec:"required"`
|
||||||
epochInterval uint64
|
epochIntervalHash common.Hash `json:"epochIntervalRoot" gencodec:"required"`
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -201,9 +266,9 @@ func (d *LCPContext) ToProto() *LCPContextProto {
|
||||||
CandidateHash: d.candidateTrie.Hash(),
|
CandidateHash: d.candidateTrie.Hash(),
|
||||||
VoteHash: d.voteTrie.Hash(),
|
VoteHash: d.voteTrie.Hash(),
|
||||||
MintCntHash: d.mintCntTrie.Hash(),
|
MintCntHash: d.mintCntTrie.Hash(),
|
||||||
period: d.period,
|
periodBlockHash: d.periodBlock.Hash(),
|
||||||
maxValidators: d.maxValidators,
|
maxValidatorsHash: d.maxValidators.Hash(),
|
||||||
epochInterval: d.epochInterval,
|
epochIntervalHash: d.epochInterval.Hash(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -214,12 +279,9 @@ func (p *LCPContextProto) Root() (h common.Hash) {
|
||||||
rlp.Encode(hw, p.CandidateHash)
|
rlp.Encode(hw, p.CandidateHash)
|
||||||
rlp.Encode(hw, p.VoteHash)
|
rlp.Encode(hw, p.VoteHash)
|
||||||
rlp.Encode(hw, p.MintCntHash)
|
rlp.Encode(hw, p.MintCntHash)
|
||||||
rlp.Encode(hw, p.period)
|
rlp.Encode(hw, p.periodBlockHash)
|
||||||
rlp.Encode(hw, p.epochInterval)
|
rlp.Encode(hw, p.maxValidatorsHash)
|
||||||
rlp.Encode(hw, p.maxValidators)
|
rlp.Encode(hw, p.epochIntervalHash)
|
||||||
rlp.Encode(hw, p.period)
|
|
||||||
rlp.Encode(hw, p.maxValidators)
|
|
||||||
rlp.Encode(hw, p.epochInterval)
|
|
||||||
hw.Sum(h[:0])
|
hw.Sum(h[:0])
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
@ -318,25 +380,38 @@ func (d *LCPContext) UnDelegate(delegatorAddr, candidateAddr common.Address) err
|
||||||
}
|
}
|
||||||
return d.voteTrie.TryDelete(delegator)
|
return d.voteTrie.TryDelete(delegator)
|
||||||
}
|
}
|
||||||
|
//function to write tries to memory and then dump to a hard drive - new in 1.8 version
|
||||||
|
func (d *LCPContext) CommitTo(onleaf trie.LeafCallback) (*LCPContextProto, error) {
|
||||||
|
epochRoot, err := d.epochTrie.Commit(onleaf)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
delegateRoot, err := d.delegateTrie.Commit(onleaf)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
voteRoot, err := d.voteTrie.Commit(onleaf)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
candidateRoot, err := d.candidateTrie.Commit(onleaf)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mintCntRoot, err := d.mintCntTrie.Commit(onleaf)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
func (d *LCPContext) CommitTo(dbw trie.DatabaseWriter) (*LCPContextProto, error) {
|
blockPeriod, err := d.periodBlock.Commit(onleaf)
|
||||||
epochRoot, err := d.epochTrie.CommitTo(dbw)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
delegateRoot, err := d.delegateTrie.CommitTo(dbw)
|
maxVal, err := d.maxValidators.Commit(onleaf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
voteRoot, err := d.voteTrie.CommitTo(dbw)
|
epochInterv, err := d.epochInterval.Commit(onleaf)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
candidateRoot, err := d.candidateTrie.CommitTo(dbw)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
mintCntRoot, err := d.mintCntTrie.CommitTo(dbw)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -346,6 +421,9 @@ func (d *LCPContext) CommitTo(dbw trie.DatabaseWriter) (*LCPContextProto, error)
|
||||||
VoteHash: voteRoot,
|
VoteHash: voteRoot,
|
||||||
CandidateHash: candidateRoot,
|
CandidateHash: candidateRoot,
|
||||||
MintCntHash: mintCntRoot,
|
MintCntHash: mintCntRoot,
|
||||||
|
periodBlockHash: blockPeriod,
|
||||||
|
maxValidatorsHash: maxVal,
|
||||||
|
epochIntervalHash: epochInterv,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -354,13 +432,17 @@ func (d *LCPContext) DelegateTrie() *trie.Trie { return d.delegateTrie
|
||||||
func (d *LCPContext) VoteTrie() *trie.Trie { return d.voteTrie }
|
func (d *LCPContext) VoteTrie() *trie.Trie { return d.voteTrie }
|
||||||
func (d *LCPContext) EpochTrie() *trie.Trie { return d.epochTrie }
|
func (d *LCPContext) EpochTrie() *trie.Trie { return d.epochTrie }
|
||||||
func (d *LCPContext) MintCntTrie() *trie.Trie { return d.mintCntTrie }
|
func (d *LCPContext) MintCntTrie() *trie.Trie { return d.mintCntTrie }
|
||||||
func (d *LCPContext) DB() ethdb.Database { return d.db }
|
func (d *LCPContext) periodTrie() *trie.Trie { return d.periodBlock }
|
||||||
|
func (d *LCPContext) maxValidatorTrie() *trie.Trie { return d.maxValidators }
|
||||||
|
func (d *LCPContext) epochIntervalTrie() *trie.Trie { return d.epochInterval }
|
||||||
|
func (d *LCPContext) DB() *trie.Database { return d.db }
|
||||||
func (dc *LCPContext) SetEpoch(epoch *trie.Trie) { dc.epochTrie = epoch }
|
func (dc *LCPContext) SetEpoch(epoch *trie.Trie) { dc.epochTrie = epoch }
|
||||||
func (dc *LCPContext) SetDelegate(delegate *trie.Trie) { dc.delegateTrie = delegate }
|
func (dc *LCPContext) SetDelegate(delegate *trie.Trie) { dc.delegateTrie = delegate }
|
||||||
func (dc *LCPContext) SetVote(vote *trie.Trie) { dc.voteTrie = vote }
|
func (dc *LCPContext) SetVote(vote *trie.Trie) { dc.voteTrie = vote }
|
||||||
func (dc *LCPContext) SetCandidate(candidate *trie.Trie) { dc.candidateTrie = candidate }
|
func (dc *LCPContext) SetCandidate(candidate *trie.Trie) { dc.candidateTrie = candidate }
|
||||||
func (dc *LCPContext) SetMintCnt(mintCnt *trie.Trie) { dc.mintCntTrie = mintCnt }
|
func (dc *LCPContext) SetMintCnt(mintCnt *trie.Trie) { dc.mintCntTrie = mintCnt }
|
||||||
|
|
||||||
|
|
||||||
func (dc *LCPContext) GetValidators() ([]common.Address, error) {
|
func (dc *LCPContext) GetValidators() ([]common.Address, error) {
|
||||||
var validators []common.Address
|
var validators []common.Address
|
||||||
key := []byte("validator")
|
key := []byte("validator")
|
||||||
|
|
@ -380,15 +462,50 @@ func (dc *LCPContext) SetValidators(validators []common.Address) error {
|
||||||
dc.epochTrie.Update(key, validatorsRLP)
|
dc.epochTrie.Update(key, validatorsRLP)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (dc *LCPContext) SetPeriod(period uint64) error {
|
|
||||||
dc.period = period
|
// Set and Get block creation speed
|
||||||
|
func (dc *LCPContext) SetPeriodBlock(period int64) error {
|
||||||
|
key:= []byte("BlockPeriod")
|
||||||
|
periodByte :=make([]byte, 8)
|
||||||
|
binary.LittleEndian.PutUint64(periodByte,uint64(period))
|
||||||
|
dc.epochTrie.Update(key, periodByte)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dc *LCPContext) GetPeriodBlock() (int64) {
|
||||||
|
key:= []byte("BlockPeriod")
|
||||||
|
periodRLP := dc.epochTrie.Get(key)
|
||||||
|
period := int64(binary.LittleEndian.Uint64(periodRLP))
|
||||||
|
return period
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set and Get maximim validators
|
||||||
|
func (dc *LCPContext) SetMaxValidators(maxVal int64) error {
|
||||||
|
key:= []byte("MaxValidators")
|
||||||
|
maxValByte :=make([]byte, 8)
|
||||||
|
binary.LittleEndian.PutUint64(maxValByte,uint64(maxVal))
|
||||||
|
dc.epochTrie.Update(key, maxValByte)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (dc *LCPContext) SetMaxValidators(maxVal uint64) error {
|
|
||||||
dc.maxValidators = maxVal
|
func (dc *LCPContext) GetMaxValidators() (int64) {
|
||||||
|
key:= []byte("MaxValidators")
|
||||||
|
maxValRLP := dc.epochTrie.Get(key)
|
||||||
|
maxVal := int64(binary.LittleEndian.Uint64(maxValRLP))
|
||||||
|
return maxVal
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set and Get epoch interval
|
||||||
|
func (dc *LCPContext) SetEpochInterval(epochInt int64) error {
|
||||||
|
key:= []byte("EpochInterval")
|
||||||
|
epochIntByte :=make([]byte, 8)
|
||||||
|
binary.LittleEndian.PutUint64(epochIntByte,uint64(epochInt))
|
||||||
|
dc.epochTrie.Update(key, epochIntByte)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (dc *LCPContext) SetEpochInterval(interval uint64) error {
|
func (dc *LCPContext) GetEpochInterval() (int64) {
|
||||||
dc.epochInterval = interval
|
key:= []byte("EpochInterval")
|
||||||
return nil
|
epochIntRLP := dc.epochTrie.Get(key)
|
||||||
|
period := int64(binary.LittleEndian.Uint64(epochIntRLP))
|
||||||
|
return period
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue