Skip to content

Conversation

Chengxuan
Copy link
Contributor

Adding support to stream confirmation events (the confirmation notification with a block event) for block listener only.

Unlike the built-in confirmation manager that's already used by the existing transaction handler, the confirmation events returned by the event stream ALWAYS return a full set of confirmations so that the consumer doesn't need to rebuild the full picture by accumulating them. This increases the size of the confirmation event, but hugely reduce the complexity of the client logic.

  • introduced a new boolean flag on GetAPIManagedEventStream, this will require all consumers to update their code

@Chengxuan Chengxuan closed this Jul 9, 2025
@Chengxuan Chengxuan deleted the add-confirm-API-es branch July 9, 2025 11:01
@Chengxuan Chengxuan reopened this Jul 9, 2025
@EnriqueL8
Copy link
Contributor

--- FAIL: TestGetAPIManagedEventStreamRetained (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xc95c54]

goroutine 8386 [running]:
testing.tRunner.func1.2({0xf48f60, 0x184b640})
	/usr/local/go/src/testing/testing.go:1632 +0x230
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1635 +0x35e
panic({0xf48f60?, 0x184b640?})
	/usr/local/go/src/runtime/panic.go:791 +0x132
github.com/hyperledger/firefly-transaction-manager/internal/events.(*eventStream).Delete(0xc000000900, {0x11fd7c0, 0xc0007f2820})
	/__w/firefly-transaction-manager/firefly-transaction-manager/internal/events/eventstream.go:742 +0x154
github.com/hyperledger/firefly-transaction-manager/pkg/fftm.(*manager).CleanupAPIManagedEventStream(0xc0001ac300, {0xc002781530, 0x24})
	/__w/firefly-transaction-manager/firefly-transaction-manager/pkg/fftm/stream_management.go:201 +0x22e
github.com/hyperledger/firefly-transaction-manager/pkg/fftm.TestGetAPIManagedEventStreamRetained(0xc00012cb60)
	/__w/firefly-transaction-manager/firefly-transaction-manager/pkg/fftm/stream_management_test.go:813 +0x29e
testing.tRunner(0xc00012cb60, 0x10f1ef8)
	/usr/local/go/src/testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 1
	/usr/local/go/src/testing/testing.go:1743 +0x390
FAIL	github.com/hyperledger/firefly-transaction-manager/pkg/fftm	0.653s

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.

A few worries about API spelling of those functions, they seem to similar but do different things - @peterbroadhurst will have some opinions here

Sad that we just released 1.4.0 and this will break consumers

Thanks for fixing the typos!

Comment on lines 48 to +49
StartConfirmedBlockListener(ctx context.Context, id *fftypes.UUID, fromBlock string, checkpoint *ffcapi.BlockListenerCheckpoint, eventStream chan<- *ffcapi.ListenerEvent) error
StartBlockConfirmationsListener(ctx context.Context, id *fftypes.UUID, fromBlock string, checkpoint *ffcapi.BlockListenerCheckpoint, eventStream chan<- *apitypes.ConfirmationsForListenerEvent) error
Copy link
Contributor

@EnriqueL8 EnriqueL8 Jul 9, 2025

Choose a reason for hiding this comment

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

Worth a comment to explain the difference, I'm still torn and think the confirmations context should be included in the ListenerEvent?

Comment on lines +382 to +384
// ListenerEvent is an event+checkpoint for a particular listener, and is the object delivered over the event stream channel when
// a new event is detected for delivery to the confirmation manager.
type ConfirmationsForListenerEvent struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

this comment needs updating

@EnriqueL8
Copy link
Contributor

Okay there is a bug here I'm fixing

time="2025-07-10T11:33:31+01:00" level=debug msg="Downloaded block header by number: 0 / bda650567b3c985689b9cef045933bb555e687424d03d91e7a96a63abb2cbd37 parent=0ca2688b1db4c51570d0a87872cfeda9c9762e23860be4d2ba482e7f74345c74" role=confirmations_ut
time="2025-07-10T11:33:31+01:00" level=debug msg="Downloaded block header by number: 1 / f6b3839a9e6b1fccda94699a0d5754d8d1a7a4feb4aea6d2c421fbd58f52a17e parent=bda650567b3c985689b9cef045933bb555e687424d03d91e7a96a63abb2cbd37" role=confirmations_ut
time="2025-07-10T11:33:31+01:00" level=debug msg="Downloaded block header by number: 2 / 8558ec3038c94c231ad42e885a354dc8944214830135b5d0267b884b071c5737 parent=f6b3839a9e6b1fccda94699a0d5754d8d1a7a4feb4aea6d2c421fbd58f52a17e" role=confirmations_ut
time="2025-07-10T11:33:31+01:00" level=debug msg="Downloaded block header by number: 3 / c02c914e97a9e27a752c713d53feeddc9d0b1c77122e2a5d386257184e7cba29 parent=8558ec3038c94c231ad42e885a354dc8944214830135b5d0267b884b071c5737" role=confirmations_ut
time="2025-07-10T11:33:31+01:00" level=debug msg="Downloaded block header by number: 4 / 7f11c986ad81bf43e5056f083f22595e6d7580df057657877929e46e35c2b72e parent=c02c914e97a9e27a752c713d53feeddc9d0b1c77122e2a5d386257184e7cba29" role=confirmations_ut
time="2025-07-10T11:33:31+01:00" level=debug msg="Downloaded block header by number: 5 / 5699aa78765cab077dc7356e28ba3c6ef7efb5009d4520aaa45ed77d91651e89 parent=7f11c986ad81bf43e5056f083f22595e6d7580df057657877929e46e35c2b72e" role=confirmations_ut
time="2025-07-10T11:33:31+01:00" level=info msg="Dispatching block 0/bda650567b3c985689b9cef045933bb555e687424d03d91e7a96a63abb2cbd37" role=confirmed_block_stream_1d1cccde-a7c4-46b9-b121-5abf990055f6
time="2025-07-10T11:33:31+01:00" level=debug msg="Downloaded block header by number: 6 / 1373b8a9f0b7e3123dff8979b7a6ec00b1744cbccd60a6b449ec8180345067ef parent=5699aa78765cab077dc7356e28ba3c6ef7efb5009d4520aaa45ed77d91651e89" role=confirmations_ut
time="2025-07-10T11:33:59+01:00" level=info msg="Dispatching block 0/bda650567b3c985689b9cef045933bb555e687424d03d91e7a96a63abb2cbd37" role=confirmed_block_stream_1d1cccde-a7c4-46b9-b121-5abf990055f6
time="2025-07-10T11:34:02+01:00" level=info msg="Dispatching block 1/f6b3839a9e6b1fccda94699a0d5754d8d1a7a4feb4aea6d2c421fbd58f52a17e" role=confirmed_block_stream_1d1cccde-a7c4-46b9-b121-5abf990055f6
time="2025-07-10T11:34:04+01:00" level=debug msg="Downloaded block header by number: 7 / 9010b8ec11725f84f661259fec5b35f64c8b130f2c5bf7bce529cdbd28d42967 parent=1373b8a9f0b7e3123dff8979b7a6ec00b1744cbccd60a6b449ec8180345067ef" role=confirmations_ut
time="2025-07-10T11:34:04+01:00" level=info msg="Dispatching block 0/bda650567b3c985689b9cef045933bb555e687424d03d91e7a96a63abb2cbd37" role=confirmed_block_stream_1d1cccde-a7c4-46b9-b121-5abf990055f6

It's dispatching the same block

@EnriqueL8
Copy link
Contributor

Okay I think I managed to fix the above, was just returning instead of breaking when we don't dispatch anything else so wasn't clearing from the blocksSinceCheckpoint the ones dispatched

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.

2 participants