@@ -128,8 +128,6 @@ var (
128128// NodeHooks defines a worker's duties at common events.
129129// These are called from the runtime's common node's worker.
130130type NodeHooks interface {
131- // Guarded by CrossNode.
132- HandleNewBlockEarlyLocked (* runtime.BlockInfo )
133131 // Guarded by CrossNode.
134132 HandleNewBlockLocked (* runtime.BlockInfo )
135133 // Guarded by CrossNode.
@@ -185,12 +183,11 @@ type Node struct {
185183
186184 // Mutable and shared between nodes' workers.
187185 // Guarded by .CrossNode.
188- CrossNode sync.Mutex
189- CurrentBlock * block.Block
190- CurrentBlockHeight int64
191- CurrentConsensusBlock * consensus.LightBlock
192- CurrentDescriptor * registry.Runtime
193- CurrentEpoch beacon.EpochTime
186+ CrossNode sync.Mutex
187+ CurrentBlock * block.Block
188+ CurrentBlockHeight int64
189+ CurrentDescriptor * registry.Runtime
190+ CurrentEpoch beacon.EpochTime
194191
195192 logger * logging.Logger
196193}
@@ -413,6 +410,13 @@ func (n *Node) handleSuspendLocked(int64) {
413410 }
414411}
415412
413+ func (n * Node ) updateHostedRuntimeVersion () {
414+ n .CrossNode .Lock ()
415+ defer n .CrossNode .Unlock ()
416+
417+ n .updateHostedRuntimeVersionLocked ()
418+ }
419+
416420func (n * Node ) updateHostedRuntimeVersionLocked () {
417421 if n .CurrentDescriptor == nil {
418422 return
@@ -465,8 +469,6 @@ func (n *Node) handleNewBlock(blk *block.Block, height int64) {
465469
466470 processedBlockCount .With (n .getMetricLabels ()).Inc ()
467471
468- header := blk .Header
469-
470472 // The first received block will be treated an epoch transition (if valid).
471473 // This will refresh the committee on the first block,
472474 // instead of waiting for the next epoch transition to occur.
@@ -487,10 +489,9 @@ func (n *Node) handleNewBlock(blk *block.Block, height int64) {
487489 // Update the current block.
488490 n .CurrentBlock = blk
489491 n .CurrentBlockHeight = height
490- n .CurrentConsensusBlock = consensusBlk
491492
492493 // Update active descriptor on epoch transitions.
493- if firstBlockReceived || header . HeaderType == block .EpochTransition || header .HeaderType == block .Suspended {
494+ if firstBlockReceived || blk . Header . HeaderType == block .EpochTransition || blk . Header .HeaderType == block .Suspended {
494495 var rs * roothash.RuntimeState
495496 rs , err = n .Consensus .RootHash ().GetRuntimeState (n .ctx , & roothash.RuntimeRequest {
496497 RuntimeID : n .Runtime .ID (),
@@ -524,19 +525,8 @@ func (n *Node) handleNewBlock(blk *block.Block, height int64) {
524525 n .KeyManagerClient .SetKeyManagerID (n .CurrentDescriptor .KeyManager )
525526 }
526527
527- bi := & runtime.BlockInfo {
528- RuntimeBlock : n .CurrentBlock ,
529- ConsensusBlock : n .CurrentConsensusBlock ,
530- Epoch : n .CurrentEpoch ,
531- ActiveDescriptor : n .CurrentDescriptor ,
532- }
533-
534- for _ , hooks := range n .hooks {
535- hooks .HandleNewBlockEarlyLocked (bi )
536- }
537-
538528 // Perform actions based on block type.
539- switch header .HeaderType {
529+ switch blk . Header .HeaderType {
540530 case block .Normal :
541531 if firstBlockReceived {
542532 n .logger .Warn ("forcing an epoch transition on first received block" )
@@ -559,11 +549,18 @@ func (n *Node) handleNewBlock(blk *block.Block, height int64) {
559549 n .handleSuspendLocked (height )
560550 default :
561551 n .logger .Error ("invalid block type" ,
562- "block" , bi . RuntimeBlock ,
552+ "block" , blk ,
563553 )
564554 return
565555 }
566556
557+ bi := & runtime.BlockInfo {
558+ RuntimeBlock : n .CurrentBlock ,
559+ ConsensusBlock : consensusBlk ,
560+ Epoch : n .CurrentEpoch ,
561+ ActiveDescriptor : n .CurrentDescriptor ,
562+ }
563+
567564 n .TxPool .ProcessBlock (bi )
568565
569566 // Fetch incoming messages.
@@ -729,9 +726,7 @@ func (n *Node) worker() {
729726
730727 // Perform initial hosted runtime version update to ensure we have something even in cases where
731728 // initial block processing fails for any reason.
732- n .CrossNode .Lock ()
733- n .updateHostedRuntimeVersionLocked ()
734- n .CrossNode .Unlock ()
729+ n .updateHostedRuntimeVersion ()
735730
736731 // Start the runtime.
737732 hrt := n .GetHostedRuntime ()
@@ -779,11 +774,7 @@ func (n *Node) worker() {
779774 return
780775 }
781776
782- func () {
783- n .CrossNode .Lock ()
784- defer n .CrossNode .Unlock ()
785- n .updateHostedRuntimeVersionLocked ()
786- }()
777+ n .updateHostedRuntimeVersion ()
787778 case compNotify .Removed != nil :
788779 // Received removal of a component.
789780 if err := n .RemoveHostedRuntimeComponent (* compNotify .Removed ); err != nil {
0 commit comments