@@ -77,6 +77,7 @@ import (
7777 "errors"
7878 "fmt"
7979
80+ "github.com/ethereum/go-ethereum/common/hexutil"
8081 "github.com/samber/lo"
8182
8283 "github.com/iotaledger/hive.go/ds/shrinkingmap"
@@ -107,7 +108,7 @@ func (o *Output) LatestActiveAnchorObject() *isc.StateAnchor {
107108 return o .cmi .latestConfirmedAO
108109}
109110func (o * Output ) LatestConfirmedAliasOutput () * isc.StateAnchor { return o .cmi .latestConfirmedAO }
110- func (o * Output ) NeedPublishTX () * shrinkingmap. ShrinkingMap [hashing. HashValue , * NeedPublishTX ] {
111+ func (o * Output ) NeedPublishTX () * NeedPublishTXMap {
111112 return o .cmi .needPublishTX
112113}
113114
@@ -132,6 +133,10 @@ const NeedConsensusKeySize = cryptolib.AddressSize + 4
132133
133134type NeedConsensusKey [NeedConsensusKeySize ]byte
134135
136+ func (nck NeedConsensusKey ) String () string {
137+ return hexutil .Encode (nck [:])
138+ }
139+
135140type NeedConsensusMap = shrinkingmap.ShrinkingMap [NeedConsensusKey , * NeedConsensus ]
136141
137142func MakeConsensusKey (committeeAddr cryptolib.Address , logIndex cmt_log.LogIndex ) NeedConsensusKey {
@@ -159,6 +164,8 @@ func (nc *NeedConsensus) String() string {
159164 )
160165}
161166
167+ type NeedPublishTXMap = shrinkingmap.ShrinkingMap [hashing.HashValue , * NeedPublishTX ]
168+
162169type NeedPublishTX struct {
163170 CommitteeAddr cryptolib.Address
164171 LogIndex cmt_log.LogIndex
@@ -187,20 +194,21 @@ type cmtLogInst struct {
187194}
188195
189196type chainMgrImpl struct {
190- chainID isc.ChainID // This instance is responsible for this chain.
191- chainStore state.Store // Store of the chain state.
192- cmtLogs map [cryptolib.AddressKey ]* cmtLogInst // All the committee log instances for this chain.
193- consensusStateRegistry cmt_log.ConsensusStateRegistry // Persistent store for log indexes.
194- latestActiveCmt * cryptolib.Address // The latest active committee.
195- latestConfirmedAO * isc.StateAnchor // The latest confirmed AO (follows Active AO).
196- activeNodesCB func () ([]* cryptolib.PublicKey , []* cryptolib.PublicKey ) // All the nodes authorized for being access nodes (for the ActiveAO).
197- trackActiveStateCB func (ao * isc.StateAnchor ) // We will call this to set new AO for the active state.
198- savePreliminaryBlockCB func (block state.Block ) // We will call this, when a preliminary block matching the tx signatures is received.
199- committeeUpdatedCB func (dkShare tcrypto.DKShare ) // Will be called, when a committee changes.
200- needConsensus * NeedConsensusMap // Query for a consensus.
201- needConsensusCB func (upd * NeedConsensusMap ) //
202- needPublishTX * shrinkingmap.ShrinkingMap [hashing.HashValue , * NeedPublishTX ] // Query to post TXes.
203- dkShareRegistryProvider registry.DKShareRegistryProvider // Source for DKShares.
197+ chainID isc.ChainID // This instance is responsible for this chain.
198+ chainStore state.Store // Store of the chain state.
199+ cmtLogs map [cryptolib.AddressKey ]* cmtLogInst // All the committee log instances for this chain.
200+ consensusStateRegistry cmt_log.ConsensusStateRegistry // Persistent store for log indexes.
201+ latestActiveCmt * cryptolib.Address // The latest active committee.
202+ latestConfirmedAO * isc.StateAnchor // The latest confirmed AO (follows Active AO).
203+ activeNodesCB func () ([]* cryptolib.PublicKey , []* cryptolib.PublicKey ) // All the nodes authorized for being access nodes (for the ActiveAO).
204+ trackActiveStateCB func (ao * isc.StateAnchor ) // We will call this to set new AO for the active state.
205+ savePreliminaryBlockCB func (block state.Block ) // We will call this, when a preliminary block matching the tx signatures is received.
206+ committeeUpdatedCB func (dkShare tcrypto.DKShare ) // Will be called, when a committee changes.
207+ needConsensus * NeedConsensusMap // Query for a consensus.
208+ needConsensusCB func (upd * NeedConsensusMap ) // A callback.
209+ needPublishTX * NeedPublishTXMap // Query to post TXes.
210+ needPublishCB func (upd * NeedPublishTXMap ) // A callback.
211+ dkShareRegistryProvider registry.DKShareRegistryProvider // Source for DKShares.
204212 varAccessNodeState VarAccessNodeState
205213 output * Output
206214 asGPA gpa.GPA
@@ -226,6 +234,7 @@ func New(
226234 dkShareRegistryProvider registry.DKShareRegistryProvider ,
227235 nodeIDFromPubKey func (pubKey * cryptolib.PublicKey ) gpa.NodeID ,
228236 needConsensusCB func (upd * NeedConsensusMap ),
237+ needPublishCB func (upd * NeedPublishTXMap ),
229238 activeNodesCB func () ([]* cryptolib.PublicKey , []* cryptolib.PublicKey ),
230239 trackActiveStateCB func (ao * isc.StateAnchor ),
231240 savePreliminaryBlockCB func (block state.Block ),
@@ -248,6 +257,7 @@ func New(
248257 needConsensus : shrinkingmap .New [NeedConsensusKey , * NeedConsensus ](),
249258 needConsensusCB : needConsensusCB ,
250259 needPublishTX : shrinkingmap .New [hashing.HashValue , * NeedPublishTX ](),
260+ needPublishCB : needPublishCB ,
251261 dkShareRegistryProvider : dkShareRegistryProvider ,
252262 varAccessNodeState : NewVarAccessNodeState (chainID , log .Named ("VAS" )),
253263 me : me ,
@@ -281,8 +291,6 @@ func (cmi *chainMgrImpl) Input(input gpa.Input) gpa.OutMessages {
281291 return cmi .handleInputConsensusOutputSkip (input )
282292 case * inputConsensusTimeout :
283293 return cmi .handleInputConsensusTimeout (input )
284- case * inputMilestoneReceived :
285- return cmi .handleInputMilestoneReceived ()
286294 case * inputCanPropose :
287295 return cmi .handleInputCanPropose ()
288296 }
@@ -358,7 +366,10 @@ func (cmi *chainMgrImpl) handleInputAnchorConfirmed(input *inputAnchorConfirmed)
358366func (cmi * chainMgrImpl ) handleInputChainTxPublishResult (input * inputChainTxPublishResult ) gpa.OutMessages {
359367 cmi .log .Debugf ("handleInputChainTxPublishResult: %+v" , input )
360368 // > Clear the TX from the NeedPublishTX variable.
361- cmi .needPublishTX .Delete (input .txHash )
369+ if cmi .needPublishTX .Has (input .txHash ) {
370+ cmi .needPublishTX .Delete (input .txHash )
371+ cmi .needPublishCB (cmi .needPublishTX )
372+ }
362373 if input .confirmed {
363374 // > If result.confirmed = false THEN ... ELSE
364375 // > NOP // AO has to be received as Confirmed AO. // TODO: Not true, anymore.
@@ -413,6 +424,7 @@ func (cmi *chainMgrImpl) handleInputConsensusOutputDone(input *inputConsensusOut
413424 Tx : input .consensusResult .Transaction ,
414425 BaseAnchorRef : baseAnchorRef ,
415426 })
427+ cmi .needPublishCB (cmi .needPublishTX )
416428 }
417429 }
418430 //
@@ -442,15 +454,6 @@ func (cmi *chainMgrImpl) handleInputConsensusTimeout(input *inputConsensusTimeou
442454 })
443455}
444456
445- func (cmi * chainMgrImpl ) handleInputMilestoneReceived () gpa.OutMessages {
446- cmi .log .Debugf ("handleInputMilestoneReceived" )
447- // TODO: This event is not needed anymore.
448- // return cmi.withAllCmtLogs(func(cl gpa.GPA) gpa.OutMessages {
449- // return cl.Input(cmt_log.NewInputMilestoneReceived())
450- // })
451- return nil
452- }
453-
454457func (cmi * chainMgrImpl ) handleInputCanPropose () gpa.OutMessages {
455458 cmi .log .Debugf ("handleInputCanPropose" )
456459 return cmi .withAllCmtLogs (func (cl gpa.GPA ) gpa.OutMessages {
0 commit comments