Skip to content

Commit 7dce6e0

Browse files
Configurable finality config
Moved finality listeners to FSC Signed-off-by: Alexandros Filios <alexandros.filios@ibm.com>
1 parent d8cb760 commit 7dce6e0

File tree

13 files changed

+531
-675
lines changed

13 files changed

+531
-675
lines changed

docs/core-token.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,53 @@ token:
2828
# leaseCleanupTickPeriod defines how often the eviction algorithm must be executed
2929
# if leaseCleanupTickPeriod is zero, the eviction algorithm is never executed
3030
leaseCleanupTickPeriod: 90s
31-
31+
# when we are interested to know when a tx reaches finality, we subscribe to the Finality Listener Manager for the finality event of that tx
32+
# this configuration specifies the way the manager is instantiated, i.e. how it gets notified about the finality events, how often it checks
33+
finality:
34+
# the implementation of the finality manager. The finality manager keeps track of all subscribers that are interested to a transaction.
35+
# These are the possible values:
36+
# delivery: The manager subscribes to the delivery service and receives all final transactions.
37+
# This manager keeps two structures: an LRU cache of recently finalized transactions, and a list of listeners that are waiting for future transactions.
38+
# When a new block comes from the delivery service, we store all new transactions in the cache and notify all interested listeners
39+
# When a client subscribes to the manager for a specific transaction, we go through the following steps, that correspond to all possible scenarios with decreasing probability:
40+
# a) The transaction reached finality recently, so we perform a lookup. If not found, we go to step b.
41+
# b) The transaction will reach finality shortly, so we append a listener and wait for a timeout. If the listener reaches timeout, we go to step c.
42+
# c) The transaction reached finality long ago, so we query the whole ledger for this specific transaction. If the query returns no result, we go to step d.
43+
# d) The transaction will reach finality at some point beyond the timeout or never, so we return Unknown. Then it is up to the client to either append another listener or accept that the transaction will never reach finality.
44+
# committer: The manager subscribes to the commit pipeline and receives all finalized transactions.
45+
# If we subscribe for a transaction that hasn't been finalized yet, we will get notified once it reaches the commit pipeline.
46+
# For listeners that haven been invoked yet, either the transaction hasn't been finalized or it was finalized before we subscribed.
47+
# For this reason, there is a periodic polling period (1s) that queries all txIDs for which there is a pending listener and invokes the listeners for the ones found.
48+
# Once we get notified about finality, we try (repeatedly) to fetch the additional tx information needed from the vault (e.g. transactionRequest)
49+
# If we work without replicas, there is no need to try more than once to fetch the additional tx information, because the finality notification and vault update happen in sync.
50+
# It is only needed in case we have replicas, where another replica may have updated the vault shortly before.
51+
type: delivery
52+
# Only applicable when type = 'committer'
53+
committer:
54+
# how many times should we try to fetch the additional tx information from the vault
55+
maxRetries: 3
56+
# how long should we wait before retrying
57+
retryWaitDuration: 5s
58+
# Only applicable when type = 'delivery'
59+
delivery:
60+
# how many goroutines should process incoming transactions in parallel. Defaults to 1
61+
mapperParallelism: 10
62+
# how many blocks can we process in parallel when they arrive from the delivery service
63+
# if the value is <= 1, then blocks are processed sequentially.
64+
# This is the suggested configuration if we are not sure about the dependencies between blocks.
65+
# The total go routines processing transactions will be blockProcessParallelism * mapperParallelism
66+
blockProcessParallelism: 1
67+
# how many transactions should we guarantee that we keep in our recent cache
68+
# if the transaction is not among these elements we proceed to the step b, as described above.
69+
# if lruSize and lruBuffer are not set, then we will never evict past transactions (the cache will grow infinitely)
70+
lruSize: 30
71+
# eviction will happen when the cache size exceeds lruSize + lruBuffer
72+
lruBuffer: 15
73+
# when we can't find a transaction in the cache most probably it is about to become final
74+
# we will listen for this amount of time and then we will query the whole ledger, as described in step c.
75+
# if the timeout is not set, then the listener will never be evicted and we will never proceed to step c.
76+
# We will wait forever for the transaction to return (as is done for the 'committer' type)
77+
listenerTimeout: 10s
3278
tms:
3379
mytms: # unique name of this token management system
3480
network: default # the name of the network this TMS refers to (Fabric, Orion, etc)

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/gin-gonic/gin v1.10.0
1010
github.com/gobuffalo/packr/v2 v2.7.1
1111
github.com/hashicorp/go-uuid v1.0.3
12-
github.com/hyperledger-labs/fabric-smart-client v0.3.1-0.20241225184208-74446d73506d
12+
github.com/hyperledger-labs/fabric-smart-client v0.3.1-0.20250106134255-d16c2938ac4f
1313
github.com/hyperledger-labs/orion-sdk-go v0.2.10
1414
github.com/hyperledger-labs/orion-server v0.2.10
1515
github.com/hyperledger/fabric v1.4.0-rc1.0.20230405174026-695dd57e01c2
@@ -38,7 +38,6 @@ require (
3838
go.uber.org/dig v1.18.0
3939
go.uber.org/zap v1.27.0
4040
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
41-
golang.org/x/sync v0.10.0
4241
google.golang.org/protobuf v1.35.1
4342
gopkg.in/yaml.v2 v2.4.0
4443
modernc.org/sqlite v1.33.1
@@ -275,6 +274,7 @@ require (
275274
golang.org/x/mod v0.21.0 // indirect
276275
golang.org/x/net v0.31.0 // indirect
277276
golang.org/x/oauth2 v0.23.0 // indirect
277+
golang.org/x/sync v0.10.0 // indirect
278278
golang.org/x/sys v0.28.0 // indirect
279279
golang.org/x/text v0.21.0 // indirect
280280
golang.org/x/time v0.5.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,8 +1070,8 @@ github.com/hidal-go/hidalgo v0.0.0-20201109092204-05749a6d73df/go.mod h1:bPkrxDl
10701070
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
10711071
github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
10721072
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
1073-
github.com/hyperledger-labs/fabric-smart-client v0.3.1-0.20241225184208-74446d73506d h1:8PpO3OG7v/uH7FLnfCGtAuiQ5YUE9xvgUy66Rd1aod8=
1074-
github.com/hyperledger-labs/fabric-smart-client v0.3.1-0.20241225184208-74446d73506d/go.mod h1:Fcz6IOEmwXihzi/Hn8fxuyAbyJxhe706+TJsQwLHRME=
1073+
github.com/hyperledger-labs/fabric-smart-client v0.3.1-0.20250106134255-d16c2938ac4f h1:sCwxAxLasNlrwfkIszj1f8gP1Th9wj9DykKh3el0weE=
1074+
github.com/hyperledger-labs/fabric-smart-client v0.3.1-0.20250106134255-d16c2938ac4f/go.mod h1:Fcz6IOEmwXihzi/Hn8fxuyAbyJxhe706+TJsQwLHRME=
10751075
github.com/hyperledger-labs/orion-sdk-go v0.2.10 h1:lFgWgxyvngIhWnIqymYGBmtmq9D6uC5d0uLG9cbyh5s=
10761076
github.com/hyperledger-labs/orion-sdk-go v0.2.10/go.mod h1:iN2xZB964AqwVJwL+EnwPOs8z1EkMEbbIg/qYeC7gDY=
10771077
github.com/hyperledger-labs/orion-server v0.2.10 h1:G4zbQEL5Egk0Oj+TwHCZWdTOLDBHOjaAEvYOT4G7ozw=

integration/nwo/token/template.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,11 @@ token:
1212
enabled: true
1313
selector:
1414
driver: {{ TokenSelector }}
15+
finality:
16+
type: delivery
17+
delivery:
18+
mapperParallelism: 10
19+
lruSize: 100
20+
lruBuffer: 50
21+
listenerTimeout: 30s
1522
`

token/services/network/fabric/committerflm.go

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)