introduce a lightweight tracking mode for connectors and update confirmation manager to cope with it#159
Conversation
Signed-off-by: Chengxuan Xing <chengxuan.xing@kaleido.io>
…ager into lightweight-confirmation-tracking
Signed-off-by: Chengxuan Xing <chengxuan.xing@kaleido.io>
| // WARNING: mutation to this list is not expected, invalid modifications will cause inefficiencies in the reconciliation process | ||
| // `rebuilt` will be true if an invalid confirmation list is detected by the reconciliation process | ||
| Confirmations []*MinimalBlockInfo `json:"confirmations,omitempty"` | ||
| Confirmations []*MinimalBlockInfo `json:"confirmations,omitempty"` // the current list of confirmations for this reconcile request, only returned when confirmation mode is set to validatedBlocks |
There was a problem hiding this comment.
What is confirmation mode and validatedBlocks? Was this previous spelling for BlockListenerTrackingMode and inMemoryPartialChain
There was a problem hiding this comment.
yes, thanks for catching it, will update the comment
| // currently the confirmation result is driven by the block listener mode, | ||
| // because when the block listener is in the headBlockNumber mode, the block information is not fetched and cached by the connector | ||
| // Therefore, it will be super inefficient to build the in memory partial chain in confirmations manager |
There was a problem hiding this comment.
Don't understand this comment sorry @Chengxuan
By currently do you mean there's a TODO? Or was this written before you implemented your change and you need to update the comment?
There was a problem hiding this comment.
No, it's a decision. I'll clean up currently
Co-authored-by: Chengxuan Xing <chengxuan.xing@kaleido.io> Signed-off-by: Chengxuan Xing <chengxuan.xing@kaleido.io>
Signed-off-by: Chengxuan Xing <chengxuan.xing@kaleido.io>
Co-authored-by: Chengxuan Xing <chengxuan.xing@kaleido.io> Signed-off-by: Chengxuan Xing <chengxuan.xing@kaleido.io>
There was a problem hiding this comment.
Marking approval, as @hosie and @Chengxuan discussed this and reached a joint reasoned proposal on the spelling of:
- The setting is
connector.chainTrackingMode, and is enabled on the the specific connector implementation (firefly-evmconnectin this case) - The two possible values are:
fulllight
These values are described in code comments on the FFTM side:
Problem
for hyperledger/firefly-evmconnect#191 and #161
Therefore, a lightweight mode is proposed to maintain the usability of transaction submission and event listeners.
Solution
This PR contains
GetBlockListenerTrackingModeinMemoryPartialChain, this is the current tracking mode, the connector builds an in-memory partical chain to track the block progress of the blockchain. This mode downloads information of each block from the chain, causing more data transportation, to provide the benefit of a verbose record of block details.headBlockNumber, this is the new tracking mode added, which is a light weight mode compared to the existinginMemoryPartialChainmode, the connector only records the head block number to track block progress. Note: this is an optional mode to opt in, the connector developer can decide whether it makes sense to add it An example implementation is proposed in EVM connector: introduce a light weight mode for tracking block progression firefly-evmconnect#190. EVM Connector also added a configuration (connector.blockTrackingMode) so that users can control which mode they'd like the connector to run under.headBlockNumbermode due to reduced information in that mode:headBlockNumber, it will no longer be able to return a list of block information. Therefore, to surface the confirmation progress, a new fieldcurrentConfirmationCounthas been introduced (alongside the existingtargetConfirmationCountfield) NOTE: it's possible to introduce a separate configuration (e.g. confirmations.confirmationMode) for confirmation manager to omit detailed block information when the connector is running ininMemoryPartialChain, but I don't see the need for it for now See the section below for details.headBlockNumbertracking modeDetails about confirmation manager changes
Add a confirmation logic that only needs the chain head block number to avoid downloading full block headers / building an in-memory partial chain.
That keeps confirmation work cheap and reduces the amount of unnecessary data downloaded from the chain.
Implementation
When the block listener is in the headBlockNumber mode, the confirmation check is derived from the head minus the receipt block number. When the required depth is reached, validity is checked by re-fetching the transaction receipt and comparing its block hash to the pending item ( this means re-org / fork handling leans on receipt reconciliation against head-driven confirmation counts rather than walking downloaded block metadata).
Example confirmation output in two modes:
Existing mode (list of blocks built using in memory chain)
Light weight mode (subset information):