Skip to content

Conversation

Chengxuan
Copy link
Contributor

@Chengxuan Chengxuan commented Sep 10, 2025

Requires hyperledger/firefly-transaction-manager#148

This PR introduced a new method, ReconcileConfirmationsForTransaction, which can be used to directly calculate the confirmation map of a given transaction.

The diagram below shows the core logic of the function:
image

Details of the confirmation Map struct can be found in this PR: hyperledger/firefly-transaction-manager#148

Reconciliation logic for an existing confirmations that get passed in

  • If the transaction is in a block hash that hasn't been recorded, that new block hash will be added to the map and a new confirmation queue will be built and stored under that block hash (map key)
  • If the transaction is in an existing block hash that's been tracked
    • If any of the existing confirmation block numbers are connectable to any of the block numbers in the current in-memory canonical chain
      • if all of them are chainable (all on the same fork or partially on the same fork), the confirmations on the same fork will be carried over into the new confirmation map, the newFork flag will be set to true in the response accordingly
    • otherwise they are discarded

Confirmation queue for different scenarios:

  • In all cases, the first item in the confirmation queue is the tx block (the block that contains the tx).
  • In the following scenario, a tx confirmation queue will have a full set of MinimalBlockInfo as the confirmation history
    • all confirmation blocks are in the current in-memory canonical chain
    • existing confirmation queue (provided by the consumer) shares a fork with the current in-memory canonical chain, all confirmation blocks, and:
      • all confirmation blocks are in the existing queue
      • or all confirmation blocks are in the existing queue + the in-memory canonical chain
    • In the following scenario, a tx confirmation queue will have partial confirmation blocks:
      • no existing confirmations provided, some confirmation blocks are ahead of the first item in the in-memory canonical chain.
      • existing confirmation queue shares a fork with current in-memory canonical chain, but it only has partial confirmation blocks in the existing confirmation queue.
    • In the scenario of the target confirmation block number of a transaction is ahead of the in-memory canonical chain or the combined existing confirmation + in-memory canonical chain blocks, the confirmation queue will only have 2 items: the tx block and the head block of the in-memory canonical chain.

Chengxuan and others added 4 commits September 11, 2025 19:21
Co-authored-by: alexey semenyuk <[email protected]>
Signed-off-by: Chengxuan Xing <[email protected]>
Signed-off-by: Chengxuan Xing <[email protected]>
Copy link
Contributor

@EnriqueL8 EnriqueL8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks really good - a few questions and suggestions but thanks for all the comments in the flow

// Note: should consider have an in-memory map of transaction hash to block for faster lookup
// The extra memory usage of the map should be outweighed by the speed improvement of lookup
// But I saw we have a ffcapi.MinimalBlockInfo struct that intentionally removes the tx hashes
// so need to figure out the reason first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you going to do this figuring out as part of the PR? I did wonder why the TX hash -> block was not a thing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, would like to, waiting for @peterbroadhurst 's input

)
}

func (bl *blockListener) validateExistingConfirmations(ctx context.Context, occ *ffcapi.ConfirmationMapUpdateResult, newQueue []*ffcapi.MinimalBlockInfo, existingConfirmations []*ffcapi.MinimalBlockInfo, currentBlock *list.Element, chainHead *ffcapi.MinimalBlockInfo, txBlockInfo *ffcapi.MinimalBlockInfo, targetConfirmationCount uint64) ([]*ffcapi.MinimalBlockInfo, *list.Element) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function was quite difficult to follow FYI

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EnriqueL8 can you elaborate exactly what's difficult to follow so we can improve it?
e.g. the algorithm used / the comments / variable naming?

Chengxuan and others added 5 commits September 15, 2025 16:04
Signed-off-by: Chengxuan Xing <[email protected]>
Signed-off-by: Chengxuan Xing <[email protected]>
Co-authored-by: Enrique Lacal <[email protected]>
Signed-off-by: Chengxuan Xing <[email protected]>
Signed-off-by: Chengxuan Xing <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants