diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-03-07 11:15:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-07 11:15:15 +0800 |
commit | 69c8d0dba506f640af4c5539fa424957cdd35db3 (patch) | |
tree | 959b4f64f651d6fca01323888d3e72a012d530e0 /core | |
parent | 0dd85e178a8a8b00c3a192c32c48547444be18dc (diff) | |
download | dexon-consensus-69c8d0dba506f640af4c5539fa424957cdd35db3.tar dexon-consensus-69c8d0dba506f640af4c5539fa424957cdd35db3.tar.gz dexon-consensus-69c8d0dba506f640af4c5539fa424957cdd35db3.tar.bz2 dexon-consensus-69c8d0dba506f640af4c5539fa424957cdd35db3.tar.lz dexon-consensus-69c8d0dba506f640af4c5539fa424957cdd35db3.tar.xz dexon-consensus-69c8d0dba506f640af4c5539fa424957cdd35db3.tar.zst dexon-consensus-69c8d0dba506f640af4c5539fa424957cdd35db3.zip |
core: PreparePayload/Witness for genesis block (#465)
Diffstat (limited to 'core')
-rw-r--r-- | core/blockchain.go | 14 | ||||
-rw-r--r-- | core/consensus.go | 5 |
2 files changed, 14 insertions, 5 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index 03c8561..30895f8 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -530,6 +530,17 @@ func (bc *blockChain) prepareBlock(position types.Position, return } else if empty { b.Timestamp = bc.dMoment + } else { + bc.logger.Debug("Calling genesis Application.PreparePayload") + if b.Payload, err = bc.app.PreparePayload(b.Position); err != nil { + b = nil + return + } + bc.logger.Debug("Calling genesis Application.PrepareWitness") + if b.Witness, err = bc.app.PrepareWitness(0); err != nil { + b = nil + return + } } } else { tipConfig := bc.tipConfig() @@ -553,12 +564,14 @@ func (bc *blockChain) prepareBlock(position types.Position, bc.logger.Debug("Calling Application.PreparePayload", "position", b.Position) if b.Payload, err = bc.app.PreparePayload(b.Position); err != nil { + b = nil return } bc.logger.Debug("Calling Application.PrepareWitness", "height", tip.Witness.Height) if b.Witness, err = bc.app.PrepareWitness( tip.Witness.Height); err != nil { + b = nil return } if !b.Timestamp.After(tip.Timestamp) { @@ -578,6 +591,7 @@ func (bc *blockChain) prepareBlock(position types.Position, } } else { if err = bc.signer.SignBlock(b); err != nil { + b = nil return } } diff --git a/core/consensus.go b/core/consensus.go index b0827fe..0f4daa7 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -41,8 +41,6 @@ var ( "hash of block is incorrect") ErrIncorrectSignature = fmt.Errorf( "signature of block is incorrect") - ErrGenesisBlockNotEmpty = fmt.Errorf( - "genesis block should be empty") ErrUnknownBlockProposed = fmt.Errorf( "unknown block is proposed") ErrIncorrectAgreementResultPosition = fmt.Errorf( @@ -1252,8 +1250,5 @@ func (con *Consensus) proposeBlock(position types.Position) ( if err = con.signer.SignCRS(b, crs); err != nil { return nil, err } - if b.IsGenesis() && len(b.Payload) != 0 { - return nil, ErrGenesisBlockNotEmpty - } return b, nil } |