aboutsummaryrefslogtreecommitdiffstats
path: root/core/consensus.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-08-10 17:32:47 +0800
committerGitHub <noreply@github.com>2018-08-10 17:32:47 +0800
commitf4690458abc24a0a3877f4facb0947c31d29e8cb (patch)
tree34ab0f3e13d4360b911832bd2fc943a7a2d2736c /core/consensus.go
parent09a0ab086cdafcb27b74e6346efdc8e96ca8145d (diff)
downloaddexon-consensus-f4690458abc24a0a3877f4facb0947c31d29e8cb.tar
dexon-consensus-f4690458abc24a0a3877f4facb0947c31d29e8cb.tar.gz
dexon-consensus-f4690458abc24a0a3877f4facb0947c31d29e8cb.tar.bz2
dexon-consensus-f4690458abc24a0a3877f4facb0947c31d29e8cb.tar.lz
dexon-consensus-f4690458abc24a0a3877f4facb0947c31d29e8cb.tar.xz
dexon-consensus-f4690458abc24a0a3877f4facb0947c31d29e8cb.tar.zst
dexon-consensus-f4690458abc24a0a3877f4facb0947c31d29e8cb.zip
core: Modify Consensus interface (#45)
Diffstat (limited to 'core/consensus.go')
-rw-r--r--core/consensus.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/core/consensus.go b/core/consensus.go
index d668c9e..bc6a2d7 100644
--- a/core/consensus.go
+++ b/core/consensus.go
@@ -26,6 +26,16 @@ import (
"github.com/dexon-foundation/dexon-consensus-core/core/types"
)
+// ErrMissingBlockInfo would be reported if some information is missing when
+// calling PrepareBlock. It implements error interface.
+type ErrMissingBlockInfo struct {
+ MissingField string
+}
+
+func (e *ErrMissingBlockInfo) Error() string {
+ return "missing " + e.MissingField + " in block"
+}
+
// Consensus implements DEXON Consensus algorithm.
type Consensus struct {
app Application
@@ -67,7 +77,8 @@ func NewConsensus(
}
// ProcessBlock is the entry point to submit one block to a Consensus instance.
-func (con *Consensus) ProcessBlock(b *types.Block) (err error) {
+func (con *Consensus) ProcessBlock(blockConv types.BlockConverter) (err error) {
+ b := blockConv.Block()
var (
deliveredBlocks []*types.Block
earlyDelivered bool
@@ -121,11 +132,18 @@ func (con *Consensus) ProcessBlock(b *types.Block) (err error) {
}
// PrepareBlock would setup header fields of block based on its ProposerID.
-func (con *Consensus) PrepareBlock(b *types.Block) (err error) {
+func (con *Consensus) PrepareBlock(blockConv types.BlockConverter,
+ proposeTime time.Time) (err error) {
+ b := blockConv.Block()
+ if (b.ProposerID == types.ValidatorID{}) {
+ err = &ErrMissingBlockInfo{MissingField: "ProposerID"}
+ return
+ }
con.lock.RLock()
defer con.lock.RUnlock()
con.rbModule.prepareBlock(b)
- b.Timestamps[b.ProposerID] = time.Now().UTC()
+ b.Timestamps[b.ProposerID] = proposeTime
+ blockConv.SetBlock(b)
return
}