MCPcopy
hub / github.com/canopy-network/canopy / CommitCertificateParallel

Method CommitCertificateParallel

controller/block.go:326–447  ·  view source on GitHub ↗

CommitCertificate() the experimental and parallelized version of the above

(qc *lib.QuorumCertificate, block *lib.Block, blockResult *lib.BlockResult, ts uint64)

Source from the content-addressed store, hash-verified

324
325// CommitCertificate() the experimental and parallelized version of the above
326func (c *Controller) CommitCertificateParallel(qc *lib.QuorumCertificate, block *lib.Block, blockResult *lib.BlockResult, ts uint64) (err lib.ErrorI) {
327 start := time.Now()
328 // cancel any running mempool check
329 c.Mempool.stop()
330 // lock the mempool
331 c.Mempool.L.Lock()
332 defer c.Mempool.L.Unlock()
333 // log the beginning of the commit
334 c.log.Debugf("TryCommit block %s", lib.BytesToString(qc.ResultsHash))
335 // cast the store to ensure the proper store type to complete this operation
336 storeI := c.FSM.Store().(lib.StoreI)
337 // reset the store once this code finishes; if code execution gets to `store.Commit()` - this will effectively be a noop
338 defer c.FSM.Reset()
339 // if the block result isn't 'pre-calculated'
340 if blockResult == nil {
341 // reset the FSM to ensure stale proposal validations don't come into play
342 c.FSM.Reset()
343 // apply the block against the state machine
344 blockResult, err = c.ApplyAndValidateBlock(block, true)
345 if err != nil {
346 // exit with error
347 return
348 }
349 }
350 // log indexing the quorum certificate
351 c.log.Debugf("Indexing certificate for height %d", qc.Header.Height)
352 // index the quorum certificate in the store
353 if err = storeI.IndexQC(qc); err != nil {
354 // exit with error
355 return
356 }
357 // log indexing the block
358 c.log.Debugf("Indexing block %d", block.BlockHeader.Height)
359 // index the block in the store
360 if err = storeI.IndexBlock(blockResult); err != nil {
361 // exit with error
362 return
363 }
364 // create an ephemeral store copy for the mempool
365 memPoolStore, err := storeI.Copy()
366 if err != nil {
367 return err
368 }
369 // increase the version number of the ephemeral store
370 memPoolStore.IncreaseVersion()
371 // delete each transaction from the mempool
372 c.Mempool.DeleteTransaction(block.Transactions...)
373 // parse committed block for straw polls
374 c.FSM.ParsePollTransactions(blockResult)
375 // if self was the proposer
376 if bytes.Equal(qc.ProposerKey, c.PublicKey) && !c.isSyncing.Load() {
377 // send the certificate results transaction on behalf of the quorum
378 c.SendCertificateResultsTx(qc)
379 }
380 // create an error group to run the commit and mempool update in parallel
381 eg := errgroup.Group{}
382 eg.Go(func() error {
383 // log the start of the commit

Callers

nothing calls this directly

Calls 15

ApplyAndValidateBlockMethod · 0.95
UpdateTelemetryMethod · 0.95
BytesToStringFunction · 0.92
BytesToTruncatedStringFunction · 0.92
NewFunction · 0.92
ErrNoValidatorsFunction · 0.92
LockMethod · 0.80
UnlockMethod · 0.80
StoreMethod · 0.80
ParsePollTransactionsMethod · 0.80
EqualMethod · 0.80

Tested by

no test coverage detected