Skip to content

Commit 957fe92

Browse files
added timstamp to root chain info update
1 parent 38ad1ef commit 957fe92

6 files changed

Lines changed: 30 additions & 10 deletions

File tree

bft/bft.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func (b *BFT) Start() {
126126
since := time.Since(resetBFT.StartTime)
127127
// allow if 'since' is less than 1 block old
128128
if int(since.Milliseconds()) < b.Config.BlockTimeMS() {
129+
b.log.Infof("Using included timestamp to calculate process time: %s", resetBFT.StartTime.String())
129130
processTime = since
130131
}
131132
// if is a root-chain update reset back to round 0 but maintain locks to prevent 'fork attacks'
@@ -897,7 +898,7 @@ type (
897898
// LoadCertificate() gets the Quorum Certificate from the chainId-> plugin at a certain height
898899
LoadCertificate(height uint64) (*lib.QuorumCertificate, lib.ErrorI)
899900
// CommitCertificate() commits a block to persistence
900-
CommitCertificate(qc *lib.QuorumCertificate, block *lib.Block, blockResult *lib.BlockResult) (err lib.ErrorI)
901+
CommitCertificate(qc *lib.QuorumCertificate, block *lib.Block, blockResult *lib.BlockResult, ts uint64) (err lib.ErrorI)
901902
// GossipBlock() is a P2P call to gossip a completed Quorum Certificate with a Proposal
902903
GossipBlock(certificate *lib.QuorumCertificate, sender []byte, timestamp uint64)
903904
// SendToSelf() is a P2P call to directly send a completed Quorum Certificate to self

bft/mock_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ type testController struct {
497497
sendToReplicasChan chan lib.Signable
498498
}
499499

500-
func (t *testController) CommitCertificate(qc *lib.QuorumCertificate, block *lib.Block, blockResult *lib.BlockResult) (err lib.ErrorI) {
500+
func (t *testController) CommitCertificate(qc *lib.QuorumCertificate, block *lib.Block, blockResult *lib.BlockResult, ts uint64) (err lib.ErrorI) {
501501
return nil
502502
}
503503

controller/block.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func (c *Controller) ValidateProposal(rcBuildHeight uint64, qc *lib.QuorumCertif
234234
// - re-checks all transactions in mempool
235235
// - atomically writes all to the underlying db
236236
// - sets up the controller for the next height
237-
func (c *Controller) CommitCertificate(qc *lib.QuorumCertificate, block *lib.Block, blockResult *lib.BlockResult) (err lib.ErrorI) {
237+
func (c *Controller) CommitCertificate(qc *lib.QuorumCertificate, block *lib.Block, blockResult *lib.BlockResult, ts uint64) (err lib.ErrorI) {
238238
start := time.Now()
239239
// cancel any running mempool check
240240
c.Mempool.stop()
@@ -319,6 +319,8 @@ func (c *Controller) CommitCertificate(qc *lib.QuorumCertificate, block *lib.Blo
319319
}
320320
continue
321321
}
322+
// set the timestamp
323+
info.Timestamp = ts
322324
// publish root chain information
323325
go c.RCManager.Publish(id, info)
324326
}
@@ -567,7 +569,7 @@ func (c *Controller) HandlePeerBlock(msg *lib.BlockMessage, syncing bool) (*lib.
567569
result = nil
568570
}
569571
// attempts to commit the QC to persistence of chain by playing it against the state machine
570-
if err = c.CommitCertificate(qc, block, result); err != nil {
572+
if err = c.CommitCertificate(qc, block, result, msg.Time); err != nil {
571573
// exit with error
572574
return nil, err
573575
}

controller/controller.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,26 @@ func (c *Controller) Stop() {
153153
// UpdateRootChainInfo() receives updates from the root-chain thread
154154
func (c *Controller) UpdateRootChainInfo(info *lib.RootChainInfo) {
155155
c.log.Debugf("Updating root chain info")
156-
//defer lib.TimeTrack(c.log, time.Now())
157156
// ensure this root chain is active
158157
activeRootChainId, _ := c.FSM.GetRootChainId()
159158
// if inactive
160159
if activeRootChainId != info.RootChainId {
161160
c.log.Debugf("Detected inactive root-chain update at rootChainId=%d", info.RootChainId)
162161
return
163162
}
163+
// set timestamp if included
164+
var timestamp time.Time
165+
// if timestamp is not 0
166+
if info.Timestamp != 0 {
167+
timestamp = time.UnixMicro(int64(info.Timestamp))
168+
}
164169
// if the last validator set is empty
165170
if info.LastValidatorSet == nil || len(info.LastValidatorSet.ValidatorSet) == 0 {
166171
// signal to reset consensus and start a new height
167-
c.Consensus.ResetBFT <- bft.ResetBFT{IsRootChainUpdate: false}
172+
c.Consensus.ResetBFT <- bft.ResetBFT{IsRootChainUpdate: false, StartTime: timestamp}
168173
} else {
169174
// signal to reset consensus
170-
c.Consensus.ResetBFT <- bft.ResetBFT{IsRootChainUpdate: true}
175+
c.Consensus.ResetBFT <- bft.ResetBFT{IsRootChainUpdate: true, StartTime: timestamp}
171176
}
172177
// update the peer 'must connect'
173178
c.UpdateP2PMustConnect(info.ValidatorSet)

lib/.proto/consensus.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,6 @@ message RootChainInfo {
166166
LotteryWinner lottery_winner = 5; // @gotags: json:"lotteryWinner"
167167
// orders: the swap order book from the 'root chain' for the 'nested chain'
168168
OrderBook orders = 6; // @gotags: json:"orders"
169+
// timestamp: a timestamp of when the notification should cause a reset
170+
uint64 timestamp = 7;
169171
}

lib/consensus.pb.go

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)