Skip to content

Commit

Permalink
Including the update for the typo fix and test fix (#3)
Browse files Browse the repository at this point in the history
* Update README.md (#1)
Signed-off-by: Ahmed Al Salih <[email protected]>

* Including the update for the typo fix and test fix
Signed-off-by: Ahmed Al Salih <[email protected]>
Co-authored-by: Ahmed Al Salih <[email protected]>
  • Loading branch information
ahmed82 authored Sep 8, 2022
1 parent 2dd6a9e commit 7a4864a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

bdls.test
cpu.out
Binary file modified cmd/emucon/emucon
Binary file not shown.
8 changes: 4 additions & 4 deletions cmd/emucon/quorum.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"keys": [
98219006221833178226499894663828536080581259993811761082380731664557876151926,
58630051888648454967792790648160553661274118301081136769104558537494738155681,
100955098131707660017796861077112074015350838580117274026874229793880529586064,
74259512097651292383407728057818570425528934348167008131707948177877498894584
68082493172628484253808951113461196766221768923883438540199548009461479956986,
44652770827640294682875208048383575561358062645764968117337703282091165609211,
80512969964988849039583604411558290822829809041684390237207179810031917243659,
55978351916851767744151875911101025920456547576858680756045508192261620541580
]
}
31 changes: 17 additions & 14 deletions consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import (
"sort"
"time"

//"fmt"

"github.com/yonggewang/bdls/crypto/blake2b"
proto "github.com/gogo/protobuf/proto"
)

const (
// ProtocolVersion is the current BDLS protocol implementation version,
// version wil be sent along with messages for protocol upgrading.
// the current BDLS protocol version,
// version will be sent along with messages for protocol upgrading.
ProtocolVersion = 1
// DefaultConsensusLatency is the default propagation latency setting for
// consensus protocol, user can adjust consensus object's latency setting
Expand All @@ -28,17 +30,18 @@ const (
)

type (
// State is the data to participant in consensus
// State is the data to participant in consensus. This could be candidate
// blocks in blockchain systems
State []byte
// StateHash is a fixed size hash to identify a state
// StateHash = H(State)
StateHash [blake2b.Size256]byte
)

// defaultHash is the system default hash function
func defaultHash(s State) StateHash { return blake2b.Sum256(s) }

type (
// consensusStage defines the status of consensus automate
// consensusStage defines the status of consensus automata
consensusStage byte
)

Expand All @@ -51,8 +54,6 @@ const (
stageLockRelease
)

// messageTuple contains a state hash, a decoded incoming message
// and it's encoded raw message with a signature.
type messageTuple struct {
StateHash StateHash // computed while adding
Message *Message // the decoded message
Expand Down Expand Up @@ -255,10 +256,10 @@ type Consensus struct {
currentRound *consensusRound // current round which has collected >=2t+1 <roundchange>

// timeouts in different stage
rcTimeout time.Time // roundchange status timeout
lockTimeout time.Time // lock status timeout
commitTimeout time.Time // commit status timeout
lockReleaseTimeout time.Time // lock-release status timeout
rcTimeout time.Time // roundchange status timeout: Delta_0
lockTimeout time.Time // lock status timeout: Delta_1
commitTimeout time.Time // commit status timeout: Delta_2
lockReleaseTimeout time.Time // lock-release status timeout: Delta_3

// locked states, along with its signatures and hashes in tuple
locks []messageTuple
Expand Down Expand Up @@ -294,7 +295,7 @@ type Consensus struct {
participants []Identity

// count num of individual identities
numIdentities int
numIdentities int //[YONGGE WANG' comments:] make sure this is synchronized with []Identity

// set to true to enable <commit> message unicast
enableCommitUnicast bool
Expand Down Expand Up @@ -1243,7 +1244,7 @@ func (c *Consensus) receiveMessage(bts []byte, now time.Time) error {
}

// for <roundchange> message, we need to find in each round
// to check if this participant has already sent <roundchange>
// to check if this sender has already sent <roundchange>
// we only keep the message from the max round.
// NOTE: we don't touch current round to prevent removing
// valid proofs.
Expand Down Expand Up @@ -1321,7 +1322,7 @@ func (c *Consensus) receiveMessage(bts []byte, now time.Time) error {

}

// for the leader, who's current round has at least 2*t+1 <roundchange>,
// for the leader, whose current round has at least 2*t+1 <roundchange>,
// we will track max proposed state for each valid added <roundchange>
if round == c.currentRound && round.NumRoundChanges() >= 2*c.t()+1 {
leaderKey := c.roundLeader(m.Round)
Expand Down Expand Up @@ -1478,6 +1479,7 @@ func (c *Consensus) receiveMessage(bts []byte, now time.Time) error {
c.rcTimeout = now.Add(c.roundchangeDuration(0))
// we sync our height and broadcast new <roundchange>.
c.broadcastRoundChange()

case MessageType_Resync:
// push the proofs in loopback device
for k := range m.Proof {
Expand All @@ -1488,6 +1490,7 @@ func (c *Consensus) receiveMessage(bts []byte, now time.Time) error {
}
c.loopback = append(c.loopback, out)
}

default:
return ErrMessageUnknownMessageType
}
Expand Down
5 changes: 5 additions & 0 deletions consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (c *Consensus) AddParticipant(key *ecdsa.PublicKey) {
}
}
c.participants = append(c.participants, coord)
c.numIdentities ++
}

// createConsensus creates a valid consensus object with given height & round and random state
Expand Down Expand Up @@ -230,13 +231,15 @@ func TestLockMessageRoundSwitch(t *testing.T) {

bts, err = proto.Marshal(sp)
assert.Nil(t, err)
consensus.numIdentities = 20
err = consensus.ReceiveMessage(bts, time.Now())
assert.Nil(t, err)
// assert length of locks to 2
assert.Equal(t, 2, len(consensus.locks))

// round switch to 12 with old B', resetting particpants
consensus.participants = nil
consensus.numIdentities = 0
_, sp, privateKey, proofKeys = createLockMessageState(t, 20, m.State, 1, 12, 1, 12)
consensus.AddParticipant(&privateKey.PublicKey)
consensus.SetLeader(&privateKey.PublicKey)
Expand All @@ -251,6 +254,7 @@ func TestLockMessageRoundSwitch(t *testing.T) {
assert.Nil(t, err)
// assert length of locks to 2
assert.Equal(t, 2, len(consensus.locks))

}

func TestLockReleaseMessageRoundSwitch(t *testing.T) {
Expand All @@ -270,6 +274,7 @@ func TestLockReleaseMessageRoundSwitch(t *testing.T) {

// round switch to 11, resetting particpants
consensus.participants = nil
consensus.numIdentities = 0
_, sp, privateKey, proofKeys = createLockReleaseMessage(t, 20, 1, 11, 1, 11)
consensus.AddParticipant(&privateKey.PublicKey)
consensus.SetLeader(&privateKey.PublicKey)
Expand Down
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var (
ErrCommitStateMismatch = errors.New("the state in <commit> message does not match what leader has locked")
ErrCommitStateValidation = errors.New("the state data validation failed <commit> message")
ErrCommitStatus = errors.New("received <commit> message in non COMMIT state")
ErrCommitHeightMismatch = errors.New("the <commit> messge has another height than expected")
ErrCommitHeightMismatch = errors.New("the <commit> message has another height than expected")
ErrCommitRoundMismatch = errors.New("the <commit> message is from another round")

// <decide> verification
Expand Down

0 comments on commit 7a4864a

Please sign in to comment.