aboutsummaryrefslogtreecommitdiffstats
path: root/core/blockchain.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-03-25 10:14:42 +0800
committerJimmy Hu <jimmy.hu@dexon.org>2019-03-27 15:25:10 +0800
commitb8ced165b1fb03394f8758e08148b0e5d06aa07b (patch)
treefa327764a4cf564bb4aa39c1570ffd7f292c7ba1 /core/blockchain.go
parent6efe199cb38eb4cb9a9a64d98ff5f8c4fb997da7 (diff)
downloaddexon-consensus-b8ced165b1fb03394f8758e08148b0e5d06aa07b.tar
dexon-consensus-b8ced165b1fb03394f8758e08148b0e5d06aa07b.tar.gz
dexon-consensus-b8ced165b1fb03394f8758e08148b0e5d06aa07b.tar.bz2
dexon-consensus-b8ced165b1fb03394f8758e08148b0e5d06aa07b.tar.lz
dexon-consensus-b8ced165b1fb03394f8758e08148b0e5d06aa07b.tar.xz
dexon-consensus-b8ced165b1fb03394f8758e08148b0e5d06aa07b.tar.zst
dexon-consensus-b8ced165b1fb03394f8758e08148b0e5d06aa07b.zip
core: Remove agreement result (#514)
* core: remove agreement result for round with randomness * remove agr test in syncer * fixup * remove randomness field from agreement result * modify test
Diffstat (limited to 'core/blockchain.go')
-rw-r--r--core/blockchain.go44
1 files changed, 13 insertions, 31 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 0ecd083..798a080 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -127,19 +127,18 @@ type tsigVerifierGetter interface {
}
type blockChain struct {
- lock sync.RWMutex
- ID types.NodeID
- lastConfirmed *types.Block
- lastDelivered *types.Block
- signer *utils.Signer
- vGetter tsigVerifierGetter
- app Application
- logger common.Logger
- pendingRandomnesses map[types.Position]*types.AgreementResult
- configs []blockChainConfig
- pendingBlocks pendingBlockRecords
- confirmedBlocks types.BlocksByPosition
- dMoment time.Time
+ lock sync.RWMutex
+ ID types.NodeID
+ lastConfirmed *types.Block
+ lastDelivered *types.Block
+ signer *utils.Signer
+ vGetter tsigVerifierGetter
+ app Application
+ logger common.Logger
+ configs []blockChainConfig
+ pendingBlocks pendingBlockRecords
+ confirmedBlocks types.BlocksByPosition
+ dMoment time.Time
}
func newBlockChain(nID types.NodeID, dMoment time.Time, initBlock *types.Block,
@@ -154,8 +153,6 @@ func newBlockChain(nID types.NodeID, dMoment time.Time, initBlock *types.Block,
app: app,
logger: logger,
dMoment: dMoment,
- pendingRandomnesses: make(
- map[types.Position]*types.AgreementResult),
}
}
@@ -228,8 +225,6 @@ func (bc *blockChain) extractBlocks() (ret []*types.Block) {
// to single chain.
c.Finalization.ParentHash = c.ParentHash
c.Finalization.Timestamp = c.Timestamp
- // It's a workaround, the height for application is one-based.
- c.Finalization.Height = c.Position.Height + 1
ret = append(ret, c)
bc.lastDelivered = c
}
@@ -290,6 +285,7 @@ func (bc *blockChain) addEmptyBlock(position types.Position) (
// to be confirmed.
panic(err)
}
+ emptyB.Finalization.Height = emptyB.Position.Height + 1
bc.confirmBlock(emptyB)
bc.checkIfBlocksConfirmed()
return emptyB
@@ -446,9 +442,6 @@ func (bc *blockChain) addPendingBlockRecord(p pendingBlockRecord) error {
}
return err
}
- if p.block != nil {
- bc.setRandomnessFromPending(p.block)
- }
return nil
}
@@ -610,17 +603,6 @@ func (bc *blockChain) confirmBlock(b *types.Block) {
bc.logger.Debug("Calling Application.BlockConfirmed", "block", b)
bc.app.BlockConfirmed(*b)
bc.lastConfirmed = b
- bc.setRandomnessFromPending(b)
bc.confirmedBlocks = append(bc.confirmedBlocks, b)
bc.purgeConfig()
}
-
-func (bc *blockChain) setRandomnessFromPending(b *types.Block) {
- if r, exist := bc.pendingRandomnesses[b.Position]; exist {
- if !r.BlockHash.Equal(b.Hash) {
- panic(fmt.Errorf("mismathed randomness: %s %s", b, r))
- }
- b.Finalization.Randomness = r.Randomness
- delete(bc.pendingRandomnesses, b.Position)
- }
-}