aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2018-09-19 18:48:41 +0800
committermissionliao <38416648+missionliao@users.noreply.github.com>2018-09-19 18:48:41 +0800
commit22e70f6da486ed6796a493f25e04679b9afa1439 (patch)
tree41998daa892812957daa58d7fe84d6fd06f4327c
parenta2a733e6f98018cb2ecc4b3982386be8892d7433 (diff)
downloadtangerine-consensus-22e70f6da486ed6796a493f25e04679b9afa1439.tar.gz
tangerine-consensus-22e70f6da486ed6796a493f25e04679b9afa1439.tar.zst
tangerine-consensus-22e70f6da486ed6796a493f25e04679b9afa1439.zip
core: rename Notary (Acks) to Witness (#118)
-rw-r--r--core/compaction-chain.go136
-rw-r--r--core/compaction-chain_test.go74
-rw-r--r--core/consensus-timestamp.go2
-rw-r--r--core/consensus-timestamp_test.go2
-rw-r--r--core/consensus.go30
-rw-r--r--core/consensus_test.go4
-rw-r--r--core/crypto.go14
-rw-r--r--core/crypto_test.go58
-rw-r--r--core/interfaces.go8
-rw-r--r--core/nonblocking-application.go14
-rw-r--r--core/nonblocking-application_test.go12
-rw-r--r--core/test/app.go32
-rw-r--r--core/test/app_test.go10
-rw-r--r--core/types/block.go8
-rw-r--r--core/types/witness.go (renamed from core/types/notary.go)32
-rw-r--r--integration_test/network.go4
-rw-r--r--simulation/app.go4
-rw-r--r--simulation/marshaller.go8
-rw-r--r--simulation/network.go8
19 files changed, 230 insertions, 230 deletions
diff --git a/core/compaction-chain.go b/core/compaction-chain.go
index 9ac52b0..c4e0f2f 100644
--- a/core/compaction-chain.go
+++ b/core/compaction-chain.go
@@ -32,28 +32,28 @@ import (
// Errors for compaction chain.
var (
- ErrNoNotaryToAck = fmt.Errorf(
- "no notary to ack")
- ErrIncorrectNotaryHash = fmt.Errorf(
- "hash of notary ack is incorrect")
- ErrIncorrectNotarySignature = fmt.Errorf(
- "signature of notary ack is incorrect")
+ ErrNoWitnessToAck = fmt.Errorf(
+ "no witness to ack")
+ ErrIncorrectWitnessHash = fmt.Errorf(
+ "hash of witness ack is incorrect")
+ ErrIncorrectWitnessSignature = fmt.Errorf(
+ "signature of witness ack is incorrect")
)
type pendingAck struct {
receivedTime time.Time
- notaryAck *types.NotaryAck
+ witnessAck *types.WitnessAck
}
type compactionChain struct {
- db blockdb.Reader
- pendingAckLock sync.RWMutex
- pendingAck map[common.Hash]*pendingAck
- prevBlockLock sync.RWMutex
- prevBlock *types.Block
- notaryAcksLock sync.RWMutex
- latestNotaryAcks map[types.ValidatorID]*types.NotaryAck
- sigToPub SigToPubFn
+ db blockdb.Reader
+ pendingAckLock sync.RWMutex
+ pendingAck map[common.Hash]*pendingAck
+ prevBlockLock sync.RWMutex
+ prevBlock *types.Block
+ witnessAcksLock sync.RWMutex
+ latestWitnessAcks map[types.ValidatorID]*types.WitnessAck
+ sigToPub SigToPubFn
}
func newCompactionChain(
@@ -61,45 +61,45 @@ func newCompactionChain(
sigToPub SigToPubFn,
) *compactionChain {
return &compactionChain{
- db: db,
- pendingAck: make(map[common.Hash]*pendingAck),
- latestNotaryAcks: make(map[types.ValidatorID]*types.NotaryAck),
- sigToPub: sigToPub,
+ db: db,
+ pendingAck: make(map[common.Hash]*pendingAck),
+ latestWitnessAcks: make(map[types.ValidatorID]*types.WitnessAck),
+ sigToPub: sigToPub,
}
}
func (cc *compactionChain) sanityCheck(
- notaryAck *types.NotaryAck, notaryBlock *types.Block) error {
- if notaryBlock != nil {
- hash, err := hashNotary(notaryBlock)
+ witnessAck *types.WitnessAck, witnessBlock *types.Block) error {
+ if witnessBlock != nil {
+ hash, err := hashWitness(witnessBlock)
if err != nil {
return err
}
- if hash != notaryAck.Hash {
- return ErrIncorrectNotaryHash
+ if hash != witnessAck.Hash {
+ return ErrIncorrectWitnessHash
}
}
- pubKey, err := cc.sigToPub(notaryAck.Hash, notaryAck.Signature)
+ pubKey, err := cc.sigToPub(witnessAck.Hash, witnessAck.Signature)
if err != nil {
return err
}
- if notaryAck.ProposerID != types.NewValidatorID(pubKey) {
- return ErrIncorrectNotarySignature
+ if witnessAck.ProposerID != types.NewValidatorID(pubKey) {
+ return ErrIncorrectWitnessSignature
}
return nil
}
-// TODO(jimmy-dexon): processBlock and prepareNotaryAck can be extraced to
+// TODO(jimmy-dexon): processBlock and prepareWitnessAck can be extraced to
// another struct.
func (cc *compactionChain) processBlock(block *types.Block) error {
prevBlock := cc.lastBlock()
if prevBlock != nil {
- hash, err := hashNotary(prevBlock)
+ hash, err := hashWitness(prevBlock)
if err != nil {
return err
}
- block.Notary.Height = prevBlock.Notary.Height + 1
- block.Notary.ParentHash = hash
+ block.Witness.Height = prevBlock.Witness.Height + 1
+ block.Witness.ParentHash = hash
}
cc.prevBlockLock.Lock()
defer cc.prevBlockLock.Unlock()
@@ -107,14 +107,14 @@ func (cc *compactionChain) processBlock(block *types.Block) error {
return nil
}
-func (cc *compactionChain) prepareNotaryAck(prvKey crypto.PrivateKey) (
- notaryAck *types.NotaryAck, err error) {
+func (cc *compactionChain) prepareWitnessAck(prvKey crypto.PrivateKey) (
+ witnessAck *types.WitnessAck, err error) {
lastBlock := cc.lastBlock()
if lastBlock == nil {
- err = ErrNoNotaryToAck
+ err = ErrNoWitnessToAck
return
}
- hash, err := hashNotary(lastBlock)
+ hash, err := hashWitness(lastBlock)
if err != nil {
return
}
@@ -122,75 +122,75 @@ func (cc *compactionChain) prepareNotaryAck(prvKey crypto.PrivateKey) (
if err != nil {
return
}
- notaryAck = &types.NotaryAck{
- ProposerID: types.NewValidatorID(prvKey.PublicKey()),
- NotaryBlockHash: lastBlock.Hash,
- Signature: sig,
- Hash: hash,
+ witnessAck = &types.WitnessAck{
+ ProposerID: types.NewValidatorID(prvKey.PublicKey()),
+ WitnessBlockHash: lastBlock.Hash,
+ Signature: sig,
+ Hash: hash,
}
return
}
-func (cc *compactionChain) processNotaryAck(notaryAck *types.NotaryAck) (
+func (cc *compactionChain) processWitnessAck(witnessAck *types.WitnessAck) (
err error) {
- // Before getting the Block from notaryAck.NotaryBlockHash, we can still
+ // Before getting the Block from witnessAck.WitnessBlockHash, we can still
// do some sanityCheck to prevent invalid ack appending to pendingAck.
- if err = cc.sanityCheck(notaryAck, nil); err != nil {
+ if err = cc.sanityCheck(witnessAck, nil); err != nil {
return
}
pendingFinished := make(chan struct{})
go func() {
- cc.processPendingNotaryAcks()
+ cc.processPendingWitnessAcks()
pendingFinished <- struct{}{}
}()
defer func() {
<-pendingFinished
}()
- notaryBlock, err := cc.db.Get(notaryAck.NotaryBlockHash)
+ witnessBlock, err := cc.db.Get(witnessAck.WitnessBlockHash)
if err != nil {
if err == blockdb.ErrBlockDoesNotExist {
cc.pendingAckLock.Lock()
defer cc.pendingAckLock.Unlock()
- cc.pendingAck[notaryAck.Hash] = &pendingAck{
+ cc.pendingAck[witnessAck.Hash] = &pendingAck{
receivedTime: time.Now().UTC(),
- notaryAck: notaryAck,
+ witnessAck: witnessAck,
}
err = nil
}
return
}
- return cc.processOneNotaryAck(notaryAck, &notaryBlock)
+ return cc.processOneWitnessAck(witnessAck, &witnessBlock)
}
-func (cc *compactionChain) processOneNotaryAck(
- notaryAck *types.NotaryAck, notaryBlock *types.Block) (
+func (cc *compactionChain) processOneWitnessAck(
+ witnessAck *types.WitnessAck, witnessBlock *types.Block) (
err error) {
- if err = cc.sanityCheck(notaryAck, notaryBlock); err != nil {
+ if err = cc.sanityCheck(witnessAck, witnessBlock); err != nil {
return
}
- lastNotaryAck, exist := func() (ack *types.NotaryAck, exist bool) {
- cc.notaryAcksLock.RLock()
- defer cc.notaryAcksLock.RUnlock()
- ack, exist = cc.latestNotaryAcks[notaryAck.ProposerID]
+ lastWitnessAck, exist := func() (ack *types.WitnessAck, exist bool) {
+ cc.witnessAcksLock.RLock()
+ defer cc.witnessAcksLock.RUnlock()
+ ack, exist = cc.latestWitnessAcks[witnessAck.ProposerID]
return
}()
if exist {
- lastNotaryBlock, err2 := cc.db.Get(lastNotaryAck.NotaryBlockHash)
+ lastWitnessBlock, err2 := cc.db.Get(lastWitnessAck.WitnessBlockHash)
err = err2
if err != nil {
return
}
- if lastNotaryBlock.Notary.Height > notaryBlock.Notary.Height {
+ if lastWitnessBlock.Witness.Height > witnessBlock.Witness.Height {
return
}
}
- cc.notaryAcksLock.Lock()
- defer cc.notaryAcksLock.Unlock()
- cc.latestNotaryAcks[notaryAck.ProposerID] = notaryAck
+ cc.witnessAcksLock.Lock()
+ defer cc.witnessAcksLock.Unlock()
+ cc.latestWitnessAcks[witnessAck.ProposerID] = witnessAck
return
}
-func (cc *compactionChain) processPendingNotaryAcks() {
+func (cc *compactionChain) processPendingWitnessAcks() {
pendingAck := func() map[common.Hash]*pendingAck {
pendingAck := make(map[common.Hash]*pendingAck)
cc.pendingAckLock.RLock()
@@ -209,7 +209,7 @@ func (cc *compactionChain) processPendingNotaryAcks() {
}
}
for hash, ack := range pendingAck {
- notaryBlock, err := cc.db.Get(ack.notaryAck.NotaryBlockHash)
+ witnessBlock, err := cc.db.Get(ack.witnessAck.WitnessBlockHash)
if err != nil {
if err == blockdb.ErrBlockDoesNotExist {
continue
@@ -219,7 +219,7 @@ func (cc *compactionChain) processPendingNotaryAcks() {
delete(pendingAck, hash)
}
delete(pendingAck, hash)
- cc.processOneNotaryAck(ack.notaryAck, &notaryBlock)
+ cc.processOneWitnessAck(ack.witnessAck, &witnessBlock)
}
cc.pendingAckLock.Lock()
@@ -230,11 +230,11 @@ func (cc *compactionChain) processPendingNotaryAcks() {
cc.pendingAck = pendingAck
}
-func (cc *compactionChain) notaryAcks() map[types.ValidatorID]*types.NotaryAck {
- cc.notaryAcksLock.RLock()
- defer cc.notaryAcksLock.RUnlock()
- acks := make(map[types.ValidatorID]*types.NotaryAck)
- for k, v := range cc.latestNotaryAcks {
+func (cc *compactionChain) witnessAcks() map[types.ValidatorID]*types.WitnessAck {
+ cc.witnessAcksLock.RLock()
+ defer cc.witnessAcksLock.RUnlock()
+ acks := make(map[types.ValidatorID]*types.WitnessAck)
+ for k, v := range cc.latestWitnessAcks {
acks[k] = v.Clone()
}
return acks
diff --git a/core/compaction-chain_test.go b/core/compaction-chain_test.go
index ae08ac0..70a368d 100644
--- a/core/compaction-chain_test.go
+++ b/core/compaction-chain_test.go
@@ -50,7 +50,7 @@ func (s *CompactionChainTestSuite) generateBlocks(
for idx := range blocks {
blocks[idx] = &types.Block{
Hash: common.NewRandomHash(),
- Notary: types.Notary{
+ Witness: types.Witness{
Timestamp: now,
},
}
@@ -70,7 +70,7 @@ func (s *CompactionChainTestSuite) TestProcessBlock() {
for idx := range blocks {
blocks[idx] = &types.Block{
Hash: common.NewRandomHash(),
- Notary: types.Notary{
+ Witness: types.Witness{
Timestamp: now,
},
}
@@ -82,35 +82,35 @@ func (s *CompactionChainTestSuite) TestProcessBlock() {
err := cc.processBlock(block)
s.Require().Nil(err)
if prevBlock != nil {
- s.Equal(block.Notary.Height, prevBlock.Notary.Height+1)
- prevHash, err := hashNotary(prevBlock)
+ s.Equal(block.Witness.Height, prevBlock.Witness.Height+1)
+ prevHash, err := hashWitness(prevBlock)
s.Require().Nil(err)
- s.Equal(prevHash, block.Notary.ParentHash)
+ s.Equal(prevHash, block.Witness.ParentHash)
}
prevBlock = block
}
}
-func (s *CompactionChainTestSuite) TestPrepareNotaryAck() {
+func (s *CompactionChainTestSuite) TestPrepareWitnessAck() {
cc := s.newCompactionChain()
blocks := s.generateBlocks(10, cc)
prv, err := eth.NewPrivateKey()
s.Require().Nil(err)
for _, block := range blocks {
- notaryAck, err := cc.prepareNotaryAck(prv)
+ witnessAck, err := cc.prepareWitnessAck(prv)
s.Require().Nil(err)
if cc.prevBlock != nil {
- s.True(verifyNotarySignature(
+ s.True(verifyWitnessSignature(
prv.PublicKey(),
cc.prevBlock,
- notaryAck.Signature))
- s.Equal(notaryAck.NotaryBlockHash, cc.prevBlock.Hash)
+ witnessAck.Signature))
+ s.Equal(witnessAck.WitnessBlockHash, cc.prevBlock.Hash)
}
cc.prevBlock = block
}
}
-func (s *CompactionChainTestSuite) TestProcessNotaryAck() {
+func (s *CompactionChainTestSuite) TestProcessWitnessAck() {
cc := s.newCompactionChain()
blocks := s.generateBlocks(10, cc)
prv1, err := eth.NewPrivateKey()
@@ -119,51 +119,51 @@ func (s *CompactionChainTestSuite) TestProcessNotaryAck() {
s.Require().Nil(err)
vID1 := types.NewValidatorID(prv1.PublicKey())
vID2 := types.NewValidatorID(prv2.PublicKey())
- notaryAcks1 := []*types.NotaryAck{}
- notaryAcks2 := []*types.NotaryAck{}
+ witnessAcks1 := []*types.WitnessAck{}
+ witnessAcks2 := []*types.WitnessAck{}
for _, block := range blocks {
cc.prevBlock = block
- notaryAck1, err := cc.prepareNotaryAck(prv1)
+ witnessAck1, err := cc.prepareWitnessAck(prv1)
s.Require().Nil(err)
- notaryAck2, err := cc.prepareNotaryAck(prv2)
+ witnessAck2, err := cc.prepareWitnessAck(prv2)
s.Require().Nil(err)
- notaryAcks1 = append(notaryAcks1, notaryAck1)
- notaryAcks2 = append(notaryAcks2, notaryAck2)
+ witnessAcks1 = append(witnessAcks1, witnessAck1)
+ witnessAcks2 = append(witnessAcks2, witnessAck2)
}
// The acked block is not yet in db.
- err = cc.processNotaryAck(notaryAcks1[0])
+ err = cc.processWitnessAck(witnessAcks1[0])
s.Nil(err)
- s.Equal(0, len(cc.notaryAcks()))
- err = cc.processNotaryAck(notaryAcks2[1])
+ s.Equal(0, len(cc.witnessAcks()))
+ err = cc.processWitnessAck(witnessAcks2[1])
s.Nil(err)
- s.Equal(0, len(cc.notaryAcks()))
- // Insert to block to db and trigger processPendingNotaryAck.
+ s.Equal(0, len(cc.witnessAcks()))
+ // Insert to block to db and trigger processPendingWitnessAck.
s.Require().Nil(s.db.Put(*blocks[0]))
s.Require().Nil(s.db.Put(*blocks[1]))
- err = cc.processNotaryAck(notaryAcks1[2])
+ err = cc.processWitnessAck(witnessAcks1[2])
s.Nil(err)
- s.Equal(2, len(cc.notaryAcks()))
+ s.Equal(2, len(cc.witnessAcks()))
- // Test the notaryAcks should be the last notaryAck.
+ // Test the witnessAcks should be the last witnessAck.
s.Require().Nil(s.db.Put(*blocks[2]))
s.Require().Nil(s.db.Put(*blocks[3]))
- s.Nil(cc.processNotaryAck(notaryAcks1[3]))
+ s.Nil(cc.processWitnessAck(witnessAcks1[3]))
- acks := cc.notaryAcks()
- s.Equal(blocks[3].Hash, acks[vID1].NotaryBlockHash)
- s.Equal(blocks[1].Hash, acks[vID2].NotaryBlockHash)
+ acks := cc.witnessAcks()
+ s.Equal(blocks[3].Hash, acks[vID1].WitnessBlockHash)
+ s.Equal(blocks[1].Hash, acks[vID2].WitnessBlockHash)
- // Test that notaryAck on less Notary.Height should be ignored.
+ // Test that witnessAck on less Witness.Height should be ignored.
s.Require().Nil(s.db.Put(*blocks[4]))
s.Require().Nil(s.db.Put(*blocks[5]))
- s.Nil(cc.processNotaryAck(notaryAcks1[5]))
- s.Nil(cc.processNotaryAck(notaryAcks2[5]))
- s.Nil(cc.processNotaryAck(notaryAcks1[4]))
- s.Nil(cc.processNotaryAck(notaryAcks2[4]))
+ s.Nil(cc.processWitnessAck(witnessAcks1[5]))
+ s.Nil(cc.processWitnessAck(witnessAcks2[5]))
+ s.Nil(cc.processWitnessAck(witnessAcks1[4]))
+ s.Nil(cc.processWitnessAck(witnessAcks2[4]))
- acks = cc.notaryAcks()
- s.Equal(blocks[5].Hash, acks[vID1].NotaryBlockHash)
- s.Equal(blocks[5].Hash, acks[vID2].NotaryBlockHash)
+ acks = cc.witnessAcks()
+ s.Equal(blocks[5].Hash, acks[vID1].WitnessBlockHash)
+ s.Equal(blocks[5].Hash, acks[vID2].WitnessBlockHash)
}
func TestCompactionChain(t *testing.T) {
diff --git a/core/consensus-timestamp.go b/core/consensus-timestamp.go
index 62bdf0c..c43ca82 100644
--- a/core/consensus-timestamp.go
+++ b/core/consensus-timestamp.go
@@ -44,7 +44,7 @@ func newConsensusTimestamp() *consensusTimestamp {
func (ct *consensusTimestamp) processBlocks(blocks []*types.Block) (err error) {
for _, block := range blocks {
if !block.IsGenesis() {
- block.Notary.Timestamp, err = getMedianTime(ct.chainTimestamps)
+ block.Witness.Timestamp, err = getMedianTime(ct.chainTimestamps)
if err != nil {
return
}
diff --git a/core/consensus-timestamp_test.go b/core/consensus-timestamp_test.go
index 56dd306..a5f9fb7 100644
--- a/core/consensus-timestamp_test.go
+++ b/core/consensus-timestamp_test.go
@@ -82,7 +82,7 @@ func (s *ConsensusTimestampTest) extractTimestamps(
if block.IsGenesis() {
continue
}
- timestamps = append(timestamps, block.Notary.Timestamp)
+ timestamps = append(timestamps, block.Witness.Timestamp)
}
return timestamps
}
diff --git a/core/consensus.go b/core/consensus.go
index 5179baf..7398628 100644
--- a/core/consensus.go
+++ b/core/consensus.go
@@ -345,8 +345,8 @@ func (con *Consensus) processMsg(
if err := blockProcesser(val); err != nil {
log.Println(err)
}
- case *types.NotaryAck:
- if err := con.ProcessNotaryAck(val); err != nil {
+ case *types.WitnessAck:
+ if err := con.ProcessWitnessAck(val); err != nil {
log.Println(err)
}
case *types.Vote:
@@ -476,22 +476,22 @@ func (con *Consensus) ProcessBlock(block *types.Block) (err error) {
if err = con.db.Update(*b); err != nil {
return
}
- con.app.DeliverBlock(b.Hash, b.Notary.Timestamp)
+ con.app.DeliverBlock(b.Hash, b.Witness.Timestamp)
// TODO(mission): Find a way to safely recycle the block.
// We should deliver block directly to
// nonBlockingApplication and let them recycle the
// block.
}
- var notaryAck *types.NotaryAck
- notaryAck, err = con.ccModule.prepareNotaryAck(con.prvKey)
+ var witnessAck *types.WitnessAck
+ witnessAck, err = con.ccModule.prepareWitnessAck(con.prvKey)
if err != nil {
return
}
- err = con.ProcessNotaryAck(notaryAck)
+ err = con.ProcessWitnessAck(witnessAck)
if err != nil {
return
}
- con.app.NotaryAckDeliver(notaryAck)
+ con.app.WitnessAckDeliver(witnessAck)
}
return
}
@@ -552,18 +552,18 @@ func (con *Consensus) PrepareGenesisBlock(b *types.Block,
return
}
-// ProcessNotaryAck is the entry point to submit one notary ack.
-func (con *Consensus) ProcessNotaryAck(notaryAck *types.NotaryAck) (err error) {
- notaryAck = notaryAck.Clone()
- if _, exists := con.gov.GetNotarySet()[notaryAck.ProposerID]; !exists {
+// ProcessWitnessAck is the entry point to submit one witness ack.
+func (con *Consensus) ProcessWitnessAck(witnessAck *types.WitnessAck) (err error) {
+ witnessAck = witnessAck.Clone()
+ if _, exists := con.gov.GetNotarySet()[witnessAck.ProposerID]; !exists {
err = ErrProposerNotValidator
return
}
- err = con.ccModule.processNotaryAck(notaryAck)
+ err = con.ccModule.processWitnessAck(witnessAck)
return
}
-// NotaryAcks returns the latest NotaryAck received from all other validators.
-func (con *Consensus) NotaryAcks() map[types.ValidatorID]*types.NotaryAck {
- return con.ccModule.notaryAcks()
+// WitnessAcks returns the latest WitnessAck received from all other validators.
+func (con *Consensus) WitnessAcks() map[types.ValidatorID]*types.WitnessAck {
+ return con.ccModule.witnessAcks()
}
diff --git a/core/consensus_test.go b/core/consensus_test.go
index dd64cc2..32f9986 100644
--- a/core/consensus_test.go
+++ b/core/consensus_test.go
@@ -41,8 +41,8 @@ func (n *network) BroadcastVote(vote *types.Vote) {}
func (n *network) BroadcastBlock(block *types.Block) {
}
-// BroadcastNotaryAck broadcasts notaryAck to all nodes in DEXON network.
-func (n *network) BroadcastNotaryAck(notaryAck *types.NotaryAck) {
+// BroadcastWitnessAck broadcasts witnessAck to all nodes in DEXON network.
+func (n *network) BroadcastWitnessAck(witnessAck *types.WitnessAck) {
}
// SendDKGPrivateShare sends PrivateShare to a DKG participant.
diff --git a/core/crypto.go b/core/crypto.go
index 8fcb118..707a2b9 100644
--- a/core/crypto.go
+++ b/core/crypto.go
@@ -25,23 +25,23 @@ import (
"github.com/dexon-foundation/dexon-consensus-core/crypto"
)
-func hashNotary(block *types.Block) (common.Hash, error) {
- binaryTime, err := block.Notary.Timestamp.MarshalBinary()
+func hashWitness(block *types.Block) (common.Hash, error) {
+ binaryTime, err := block.Witness.Timestamp.MarshalBinary()
if err != nil {
return common.Hash{}, err
}
binaryHeight := make([]byte, 8)
- binary.LittleEndian.PutUint64(binaryHeight, block.Notary.Height)
+ binary.LittleEndian.PutUint64(binaryHeight, block.Witness.Height)
hash := crypto.Keccak256Hash(
- block.Notary.ParentHash[:],
+ block.Witness.ParentHash[:],
binaryTime,
binaryHeight)
return hash, nil
}
-func verifyNotarySignature(pubkey crypto.PublicKey,
- notaryBlock *types.Block, sig crypto.Signature) (bool, error) {
- hash, err := hashNotary(notaryBlock)
+func verifyWitnessSignature(pubkey crypto.PublicKey,
+ witnessBlock *types.Block, sig crypto.Signature) (bool, error) {
+ hash, err := hashWitness(witnessBlock)
if err != nil {
return false, err
}
diff --git a/core/crypto_test.go b/core/crypto_test.go
index 7f3c3f3..fe6bbc1 100644
--- a/core/crypto_test.go
+++ b/core/crypto_test.go
@@ -42,13 +42,13 @@ func (s *CryptoTestSuite) prepareBlock(prevBlock *types.Block) *types.Block {
return &types.Block{
Acks: common.NewSortedHashes(acks),
Timestamp: now,
- Notary: types.Notary{
+ Witness: types.Witness{
Timestamp: time.Now(),
Height: 0,
},
}
}
- parentHash, err := hashNotary(prevBlock)
+ parentHash, err := hashWitness(prevBlock)
s.Require().Nil(err)
s.Require().NotEqual(prevBlock.Hash, common.Hash{})
acks = append(acks, parentHash)
@@ -59,10 +59,10 @@ func (s *CryptoTestSuite) prepareBlock(prevBlock *types.Block) *types.Block {
Position: types.Position{
Height: prevBlock.Position.Height + 1,
},
- Notary: types.Notary{
+ Witness: types.Witness{
ParentHash: parentHash,
Timestamp: time.Now(),
- Height: prevBlock.Notary.Height + 1,
+ Height: prevBlock.Witness.Height + 1,
},
}
}
@@ -77,61 +77,61 @@ func (s *CryptoTestSuite) newBlock(prevBlock *types.Block) *types.Block {
func (s *CryptoTestSuite) generateCompactionChain(
length int, prv crypto.PrivateKey) (
- []*types.Block, []types.NotaryAck) {
+ []*types.Block, []types.WitnessAck) {
blocks := make([]*types.Block, length)
- notaryAcks := make([]types.NotaryAck, length)
+ witnessAcks := make([]types.WitnessAck, length)
var prevBlock *types.Block
for idx := range blocks {
block := s.newBlock(prevBlock)
prevBlock = block
blocks[idx] = block
var err error
- notaryAcks[idx].Hash, err = hashNotary(blocks[idx])
+ witnessAcks[idx].Hash, err = hashWitness(blocks[idx])
s.Require().Nil(err)
- notaryAcks[idx].NotaryBlockHash = blocks[idx].Hash
- notaryAcks[idx].Signature, err = prv.Sign(notaryAcks[idx].Hash)
+ witnessAcks[idx].WitnessBlockHash = blocks[idx].Hash
+ witnessAcks[idx].Signature, err = prv.Sign(witnessAcks[idx].Hash)
s.Require().Nil(err)
if idx > 0 {
- block.Notary.ParentHash = notaryAcks[idx-1].Hash
+ block.Witness.ParentHash = witnessAcks[idx-1].Hash
}
}
- return blocks, notaryAcks
+ return blocks, witnessAcks
}
-func (s *CryptoTestSuite) TestNotaryAckSignature() {
+func (s *CryptoTestSuite) TestWitnessAckSignature() {
prv, err := eth.NewPrivateKey()
pub := prv.PublicKey()
s.Require().Nil(err)
- blocks, notaryAcks := s.generateCompactionChain(10, prv)
+ blocks, witnessAcks := s.generateCompactionChain(10, prv)
blockMap := make(map[common.Hash]*types.Block)
for _, block := range blocks {
blockMap[block.Hash] = block
}
parentBlock := blocks[0]
- for _, notaryAck := range notaryAcks {
- notaryBlock, exist := blockMap[notaryAck.NotaryBlockHash]
+ for _, witnessAck := range witnessAcks {
+ witnessBlock, exist := blockMap[witnessAck.WitnessBlockHash]
s.Require().True(exist)
- if notaryBlock.Notary.Height == 0 {
+ if witnessBlock.Witness.Height == 0 {
continue
}
- s.True(parentBlock.Notary.Height == notaryBlock.Notary.Height-1)
- hash, err := hashNotary(parentBlock)
+ s.True(parentBlock.Witness.Height == witnessBlock.Witness.Height-1)
+ hash, err := hashWitness(parentBlock)
s.Require().Nil(err)
- s.Equal(hash, notaryBlock.Notary.ParentHash)
- s.True(verifyNotarySignature(
- pub, notaryBlock, notaryAck.Signature))
- parentBlock = notaryBlock
+ s.Equal(hash, witnessBlock.Witness.ParentHash)
+ s.True(verifyWitnessSignature(
+ pub, witnessBlock, witnessAck.Signature))
+ parentBlock = witnessBlock
}
- // Modify Block.Notary.Timestamp and verify signature again.
- for _, notaryAck := range notaryAcks {
- block, exist := blockMap[notaryAck.NotaryBlockHash]
+ // Modify Block.Witness.Timestamp and verify signature again.
+ for _, witnessAck := range witnessAcks {
+ block, exist := blockMap[witnessAck.WitnessBlockHash]
s.Require().True(exist)
- block.Notary.Timestamp = time.Time{}
- ackingBlock, exist := blockMap[notaryAck.NotaryBlockHash]
+ block.Witness.Timestamp = time.Time{}
+ ackingBlock, exist := blockMap[witnessAck.WitnessBlockHash]
s.Require().True(exist)
- s.False(verifyNotarySignature(
- pub, ackingBlock, notaryAck.Signature))
+ s.False(verifyWitnessSignature(
+ pub, ackingBlock, witnessAck.Signature))
}
}
diff --git a/core/interfaces.go b/core/interfaces.go
index 0a8ca8f..3fae590 100644
--- a/core/interfaces.go
+++ b/core/interfaces.go
@@ -46,8 +46,8 @@ type Application interface {
// DeliverBlock is called when a block is add to the compaction chain.
DeliverBlock(blockHash common.Hash, timestamp time.Time)
- // NotaryAckDeliver is called when a notary ack is created.
- NotaryAckDeliver(notaryAck *types.NotaryAck)
+ // WitnessAckDeliver is called when a witness ack is created.
+ WitnessAckDeliver(witnessAck *types.WitnessAck)
}
// Network describs the network interface that interacts with DEXON consensus
@@ -59,8 +59,8 @@ type Network interface {
// BroadcastBlock broadcasts block to all nodes in DEXON network.
BroadcastBlock(block *types.Block)
- // BroadcastNotaryAck broadcasts notaryAck to all nodes in DEXON network.
- BroadcastNotaryAck(notaryAck *types.NotaryAck)
+ // BroadcastWitnessAck broadcasts witnessAck to all nodes in DEXON network.
+ BroadcastWitnessAck(witnessAck *types.WitnessAck)
// SendDKGPrivateShare sends PrivateShare to a DKG participant.
SendDKGPrivateShare(recv types.ValidatorID, prvShare *types.DKGPrivateShare)
diff --git a/core/nonblocking-application.go b/core/nonblocking-application.go
index cb83b17..2226eb0 100644
--- a/core/nonblocking-application.go
+++ b/core/nonblocking-application.go
@@ -44,8 +44,8 @@ type deliverBlockEvent struct {
timestamp time.Time
}
-type notaryAckEvent struct {
- notaryAck *types.NotaryAck
+type witnessAckEvent struct {
+ witnessAck *types.WitnessAck
}
// nonBlockingApplication implements Application and is a decorator for
@@ -100,8 +100,8 @@ func (app *nonBlockingApplication) run() {
app.app.TotalOrderingDeliver(e.blockHashes, e.early)
case deliverBlockEvent:
app.app.DeliverBlock(e.blockHash, e.timestamp)
- case notaryAckEvent:
- app.app.NotaryAckDeliver(e.notaryAck)
+ case witnessAckEvent:
+ app.app.WitnessAckDeliver(e.witnessAck)
default:
fmt.Printf("Unknown event %v.", e)
}
@@ -154,7 +154,7 @@ func (app *nonBlockingApplication) DeliverBlock(
app.addEvent(deliverBlockEvent{blockHash, timestamp})
}
-// NotaryAckDeliver is called when a notary ack is created.
-func (app *nonBlockingApplication) NotaryAckDeliver(notaryAck *types.NotaryAck) {
- app.addEvent(notaryAckEvent{notaryAck})
+// WitnessAckDeliver is called when a witness ack is created.
+func (app *nonBlockingApplication) WitnessAckDeliver(witnessAck *types.WitnessAck) {
+ app.addEvent(witnessAckEvent{witnessAck})
}
diff --git a/core/nonblocking-application_test.go b/core/nonblocking-application_test.go
index a969530..82b3f2c 100644
--- a/core/nonblocking-application_test.go
+++ b/core/nonblocking-application_test.go
@@ -33,7 +33,7 @@ type slowApp struct {
stronglyAcked map[common.Hash]struct{}
totalOrderingDeliver map[common.Hash]struct{}
deliverBlock map[common.Hash]struct{}
- notaryAck map[common.Hash]struct{}
+ witnessAck map[common.Hash]struct{}
}
func newSlowApp(sleep time.Duration) *slowApp {
@@ -43,7 +43,7 @@ func newSlowApp(sleep time.Duration) *slowApp {
stronglyAcked: make(map[common.Hash]struct{}),
totalOrderingDeliver: make(map[common.Hash]struct{}),
deliverBlock: make(map[common.Hash]struct{}),
- notaryAck: make(map[common.Hash]struct{}),
+ witnessAck: make(map[common.Hash]struct{}),
}
}
@@ -77,9 +77,9 @@ func (app *slowApp) DeliverBlock(blockHash common.Hash, timestamp time.Time) {
app.deliverBlock[blockHash] = struct{}{}
}
-func (app *slowApp) NotaryAckDeliver(notaryAck *types.NotaryAck) {
+func (app *slowApp) WitnessAckDeliver(witnessAck *types.WitnessAck) {
time.Sleep(app.sleep)
- app.notaryAck[notaryAck.Hash] = struct{}{}
+ app.witnessAck[witnessAck.Hash] = struct{}{}
}
type NonBlockingAppTestSuite struct {
@@ -102,7 +102,7 @@ func (s *NonBlockingAppTestSuite) TestNonBlockingApplication() {
nbapp.BlockConfirmed(&types.Block{Hash: hash})
nbapp.StronglyAcked(hash)
nbapp.DeliverBlock(hash, time.Now().UTC())
- nbapp.NotaryAckDeliver(&types.NotaryAck{Hash: hash})
+ nbapp.WitnessAckDeliver(&types.WitnessAck{Hash: hash})
}
nbapp.TotalOrderingDeliver(hashes, true)
@@ -115,7 +115,7 @@ func (s *NonBlockingAppTestSuite) TestNonBlockingApplication() {
s.Contains(app.stronglyAcked, hash)
s.Contains(app.totalOrderingDeliver, hash)
s.Contains(app.deliverBlock, hash)
- s.Contains(app.notaryAck, hash)
+ s.Contains(app.witnessAck, hash)
}
}
diff --git a/core/test/app.go b/core/test/app.go
index 57fc467..e9ef871 100644
--- a/core/test/app.go
+++ b/core/test/app.go
@@ -50,10 +50,10 @@ var (
// and delivered are different.
ErrMismatchTotalOrderingAndDelivered = fmt.Errorf(
"mismatch total ordering and delivered sequence")
- // ErrNotaryAckUnknownBlock means the notary ack is acking on the unknown
+ // ErrWitnessAckUnknownBlock means the witness ack is acking on the unknown
// block.
- ErrNotaryAckUnknownBlock = fmt.Errorf(
- "notary ack on unknown block")
+ ErrWitnessAckUnknownBlock = fmt.Errorf(
+ "witness ack on unknown block")
)
// AppAckedRecord caches information when this application received
@@ -87,8 +87,8 @@ type App struct {
Delivered map[common.Hash]*AppDeliveredRecord
DeliverSequence common.Hashes
deliveredLock sync.RWMutex
- NotaryAckSequence []*types.NotaryAck
- notaryAckLock sync.RWMutex
+ WitnessAckSequence []*types.WitnessAck
+ witnessAckLock sync.RWMutex
}
// NewApp constructs a TestApp instance.
@@ -155,12 +155,12 @@ func (app *App) DeliverBlock(blockHash common.Hash, timestamp time.Time) {
app.DeliverSequence = append(app.DeliverSequence, blockHash)
}
-// NotaryAckDeliver implements Application interface.
-func (app *App) NotaryAckDeliver(notaryAck *types.NotaryAck) {
- app.notaryAckLock.Lock()
- defer app.notaryAckLock.Unlock()
+// WitnessAckDeliver implements Application interface.
+func (app *App) WitnessAckDeliver(witnessAck *types.WitnessAck) {
+ app.witnessAckLock.Lock()
+ defer app.witnessAckLock.Unlock()
- app.NotaryAckSequence = append(app.NotaryAckSequence, notaryAck)
+ app.WitnessAckSequence = append(app.WitnessAckSequence, witnessAck)
}
// Compare performs these checks against another App instance
@@ -249,12 +249,12 @@ Loop:
return ErrMismatchTotalOrderingAndDelivered
}
- // Make sure that notaryAck is acking the correct block.
- app.notaryAckLock.RLock()
- defer app.notaryAckLock.RUnlock()
- for _, notaryAck := range app.NotaryAckSequence {
- if _, exists := app.Delivered[notaryAck.NotaryBlockHash]; !exists {
- return ErrNotaryAckUnknownBlock
+ // Make sure that witnessAck is acking the correct block.
+ app.witnessAckLock.RLock()
+ defer app.witnessAckLock.RUnlock()
+ for _, witnessAck := range app.WitnessAckSequence {
+ if _, exists := app.Delivered[witnessAck.WitnessBlockHash]; !exists {
+ return ErrWitnessAckUnknownBlock
}
}
return nil
diff --git a/core/test/app_test.go b/core/test/app_test.go
index 6966de5..0003852 100644
--- a/core/test/app_test.go
+++ b/core/test/app_test.go
@@ -153,14 +153,14 @@ func (s *AppTestSuite) TestVerify() {
app4.StronglyAcked(hash)
app4.TotalOrderingDeliver(common.Hashes{hash}, false)
s.deliverBlockWithTimeFromSequenceLength(app4, hash)
- // Notary ack on unknown block.
+ // Witness ack on unknown block.
app5 := NewApp()
s.setupAppByTotalOrderDeliver(app5, s.to1)
- app5.NotaryAckDeliver(&types.NotaryAck{
- Hash: common.NewRandomHash(),
- NotaryBlockHash: common.NewRandomHash(),
+ app5.WitnessAckDeliver(&types.WitnessAck{
+ Hash: common.NewRandomHash(),
+ WitnessBlockHash: common.NewRandomHash(),
})
- req.Equal(ErrNotaryAckUnknownBlock, app5.Verify())
+ req.Equal(ErrWitnessAckUnknownBlock, app5.Verify())
}
func TestApp(t *testing.T) {
diff --git a/core/types/block.go b/core/types/block.go
index e00465c..61cb458 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -15,7 +15,7 @@
// along with the dexon-consensus-core library. If not, see
// <http://www.gnu.org/licenses/>.
-// TODO(jimmy-dexon): remove comments of NotaryAck before open source.
+// TODO(jimmy-dexon): remove comments of WitnessAck before open source.
package types
@@ -65,7 +65,7 @@ type Block struct {
CRSSignature crypto.Signature `json:"crs_signature"`
- Notary Notary `json:"notary"`
+ Witness Witness `json:"witness"`
}
func (b *Block) String() string {
@@ -84,8 +84,8 @@ func (b *Block) Clone() (bcopy *Block) {
bcopy.Position.Height = b.Position.Height
bcopy.Signature = b.Signature.Clone()
bcopy.CRSSignature = b.CRSSignature.Clone()
- bcopy.Notary.Timestamp = b.Notary.Timestamp
- bcopy.Notary.Height = b.Notary.Height
+ bcopy.Witness.Timestamp = b.Witness.Timestamp
+ bcopy.Witness.Height = b.Witness.Height
bcopy.Timestamp = b.Timestamp
bcopy.Acks = make(common.SortedHashes, len(b.Acks))
copy(bcopy.Acks, b.Acks)
diff --git a/core/types/notary.go b/core/types/witness.go
index 216466c..1e432f6 100644
--- a/core/types/notary.go
+++ b/core/types/witness.go
@@ -15,7 +15,7 @@
// along with the dexon-consensus-core library. If not, see
// <http://www.gnu.org/licenses/>.
-// TODO(jimmy-dexon): remove comments of NotaryAck before open source.
+// TODO(jimmy-dexon): remove comments of WitnessAck before open source.
package types
@@ -26,27 +26,27 @@ import (
"github.com/dexon-foundation/dexon-consensus-core/crypto"
)
-// NotaryAck represents the acking to the compaction chain.
-type NotaryAck struct {
- ProposerID ValidatorID `json:"proposer_id"`
- NotaryBlockHash common.Hash `json:"notary_block_hash"`
- Hash common.Hash `json:"hash"`
- // NotarySignature is the signature of the hash value of BlockNotary.
+// WitnessAck represents the acking to the compaction chain.
+type WitnessAck struct {
+ ProposerID ValidatorID `json:"proposer_id"`
+ WitnessBlockHash common.Hash `json:"witness_block_hash"`
+ Hash common.Hash `json:"hash"`
+ // WitnessSignature is the signature of the hash value of BlockWitness.
Signature crypto.Signature `json:"signature"`
}
-// Clone returns a deep copy of a NotaryAck.
-func (a *NotaryAck) Clone() *NotaryAck {
- return &NotaryAck{
- ProposerID: a.ProposerID,
- NotaryBlockHash: a.NotaryBlockHash,
- Hash: a.Hash,
- Signature: a.Signature,
+// Clone returns a deep copy of a WitnessAck.
+func (a *WitnessAck) Clone() *WitnessAck {
+ return &WitnessAck{
+ ProposerID: a.ProposerID,
+ WitnessBlockHash: a.WitnessBlockHash,
+ Hash: a.Hash,
+ Signature: a.Signature,
}
}
-// Notary represents the consensus information on the compaction chain.
-type Notary struct {
+// Witness represents the consensus information on the compaction chain.
+type Witness struct {
ParentHash common.Hash `json:"parent_hash"`
Timestamp time.Time `json:"timestamp"`
Height uint64 `json:"height"`
diff --git a/integration_test/network.go b/integration_test/network.go
index 735d48a..b58cbcd 100644
--- a/integration_test/network.go
+++ b/integration_test/network.go
@@ -32,8 +32,8 @@ func (n *Network) BroadcastVote(vote *types.Vote) {}
func (n *Network) BroadcastBlock(block *types.Block) {
}
-// BroadcastNotaryAck broadcasts notaryAck to all nodes in DEXON network.
-func (n *Network) BroadcastNotaryAck(notaryAck *types.NotaryAck) {
+// BroadcastWitnessAck broadcasts witnessAck to all nodes in DEXON network.
+func (n *Network) BroadcastWitnessAck(witnessAck *types.WitnessAck) {
}
// SendDKGPrivateShare sends PrivateShare to a DKG participant.
diff --git a/simulation/app.go b/simulation/app.go
index 9e89516..87672fd 100644
--- a/simulation/app.go
+++ b/simulation/app.go
@@ -195,6 +195,6 @@ func (a *simApp) DeliverBlock(blockHash common.Hash, timestamp time.Time) {
a.netModule.report(msg)
}
-// NotaryAckDeliver is called when a notary ack is created.
-func (a *simApp) NotaryAckDeliver(notaryAck *types.NotaryAck) {
+// WitnessAckDeliver is called when a witness ack is created.
+func (a *simApp) WitnessAckDeliver(witnessAck *types.WitnessAck) {
}
diff --git a/simulation/marshaller.go b/simulation/marshaller.go
index ad16419..45a186d 100644
--- a/simulation/marshaller.go
+++ b/simulation/marshaller.go
@@ -57,8 +57,8 @@ func (m *jsonMarshaller) Unmarshal(
break
}
msg = block
- case "notary-ack":
- nAck := &types.NotaryAck{}
+ case "witness-ack":
+ nAck := &types.WitnessAck{}
if err = json.Unmarshal(payload, nAck); err != nil {
break
}
@@ -109,8 +109,8 @@ func (m *jsonMarshaller) Marshal(msg interface{}) (
msgType = "info-status"
case *types.Block:
msgType = "block"
- case *types.NotaryAck:
- msgType = "notary-ack"
+ case *types.WitnessAck:
+ msgType = "witness-ack"
case *types.Vote:
msgType = "vote"
case *types.DKGPrivateShare:
diff --git a/simulation/network.go b/simulation/network.go
index 83c4daf..ce6ea65 100644
--- a/simulation/network.go
+++ b/simulation/network.go
@@ -131,9 +131,9 @@ func (n *network) BroadcastBlock(block *types.Block) {
}
}
-// BroadcastNotaryAck implements core.Network interface.
-func (n *network) BroadcastNotaryAck(notaryAck *types.NotaryAck) {
- if err := n.trans.Broadcast(notaryAck); err != nil {
+// BroadcastWitnessAck implements core.Network interface.
+func (n *network) BroadcastWitnessAck(witnessAck *types.WitnessAck) {
+ if err := n.trans.Broadcast(witnessAck); err != nil {
panic(err)
}
}
@@ -188,7 +188,7 @@ func (n *network) run() {
// to consensus or validator, that's the question.
disp := func(e *test.TransportEnvelope) {
switch e.Msg.(type) {
- case *types.Block, *types.Vote, *types.NotaryAck,
+ case *types.Block, *types.Vote, *types.WitnessAck,
*types.DKGPrivateShare, *types.DKGPartialSignature:
n.toConsensus <- e.Msg
default: