mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-05-18 08:19:26 +00:00
feat: no need to indexing of sync strategy
This commit is contained in:
parent
97c1c1c7e7
commit
b7e23842fe
@ -68,7 +68,6 @@ type
|
|||||||
validRootBuffer*: Deque[MerkleNode]
|
validRootBuffer*: Deque[MerkleNode]
|
||||||
# interval loop to shut down gracefully
|
# interval loop to shut down gracefully
|
||||||
blockFetchingActive*: bool
|
blockFetchingActive*: bool
|
||||||
merkleProofsByIndex*: Table[Uint256, seq[Uint256]]
|
|
||||||
|
|
||||||
const DefaultKeyStorePath* = "rlnKeystore.json"
|
const DefaultKeyStorePath* = "rlnKeystore.json"
|
||||||
const DefaultKeyStorePassword* = "password"
|
const DefaultKeyStorePassword* = "password"
|
||||||
@ -92,16 +91,6 @@ template retryWrapper(
|
|||||||
retryWrapper(res, RetryStrategy.new(), errStr, g.onFatalErrorAction):
|
retryWrapper(res, RetryStrategy.new(), errStr, g.onFatalErrorAction):
|
||||||
body
|
body
|
||||||
|
|
||||||
proc fetchMerkleProof*(g: OnchainGroupManager, index: Uint256) {.async.} =
|
|
||||||
## Fetches and caches the Merkle proof elements for a given index
|
|
||||||
try:
|
|
||||||
let merkleProofInvocation = g.wakuRlnContract.get().merkleProofElements(index)
|
|
||||||
let merkleProof = await merkleProofInvocation.call()
|
|
||||||
# Await the contract call and extract the result
|
|
||||||
g.merkleProofsByIndex[index] = merkleProof
|
|
||||||
except CatchableError:
|
|
||||||
error "Failed to fetch merkle proof: " & getCurrentExceptionMsg()
|
|
||||||
|
|
||||||
proc setMetadata*(
|
proc setMetadata*(
|
||||||
g: OnchainGroupManager, lastProcessedBlock = none(BlockNumber)
|
g: OnchainGroupManager, lastProcessedBlock = none(BlockNumber)
|
||||||
): GroupManagerResult[void] =
|
): GroupManagerResult[void] =
|
||||||
@ -361,10 +350,6 @@ proc handleEvents(
|
|||||||
toRemoveIndices = removalIndices,
|
toRemoveIndices = removalIndices,
|
||||||
)
|
)
|
||||||
|
|
||||||
for i in 0 ..< rateCommitments.len:
|
|
||||||
let index = startIndex + MembershipIndex(i)
|
|
||||||
await g.fetchMerkleProof(stuint(index, 256))
|
|
||||||
|
|
||||||
g.latestIndex = startIndex + MembershipIndex(rateCommitments.len)
|
g.latestIndex = startIndex + MembershipIndex(rateCommitments.len)
|
||||||
trace "new members added to the Merkle tree",
|
trace "new members added to the Merkle tree",
|
||||||
commitments = rateCommitments.mapIt(it.inHex)
|
commitments = rateCommitments.mapIt(it.inHex)
|
||||||
@ -385,12 +370,6 @@ proc handleRemovedEvents(
|
|||||||
if members.anyIt(it[1]):
|
if members.anyIt(it[1]):
|
||||||
numRemovedBlocks += 1
|
numRemovedBlocks += 1
|
||||||
|
|
||||||
# Remove cached merkleProof for each removed member
|
|
||||||
for member in members:
|
|
||||||
if member[1]: # Check if the member is removed
|
|
||||||
let index = member[0].index
|
|
||||||
g.merkleProofsByIndex.del(stuint(index, 256))
|
|
||||||
|
|
||||||
await g.backfillRootQueue(numRemovedBlocks)
|
await g.backfillRootQueue(numRemovedBlocks)
|
||||||
|
|
||||||
proc getAndHandleEvents(
|
proc getAndHandleEvents(
|
||||||
|
|||||||
@ -13,8 +13,16 @@ logScope:
|
|||||||
topics = "waku rln_relay onchain_sync_group_manager"
|
topics = "waku rln_relay onchain_sync_group_manager"
|
||||||
|
|
||||||
type OnChainSyncGroupManager* = ref object of OnchainGroupManager
|
type OnChainSyncGroupManager* = ref object of OnchainGroupManager
|
||||||
# Cache for merkle proofs by index
|
|
||||||
merkleProofsByIndex*: Table[Uint256, seq[Uint256]]
|
proc fetchMerkleProof*(g: OnchainSyncGroupManager) {.async.} =
|
||||||
|
let index = stuint(g.membershipIndex.get(), 256)
|
||||||
|
try:
|
||||||
|
let merkleProofInvocation = g.wakuRlnContract.get().merkleProofElements(index)
|
||||||
|
let merkleProof = await merkleProofInvocation.call()
|
||||||
|
# Await the contract call and extract the result
|
||||||
|
return merkleProof
|
||||||
|
except CatchableError:
|
||||||
|
error "Failed to fetch merkle proof: " & getCurrentExceptionMsg()
|
||||||
|
|
||||||
method generateProof*(
|
method generateProof*(
|
||||||
g: OnChainSyncGroupManager,
|
g: OnChainSyncGroupManager,
|
||||||
@ -32,20 +40,7 @@ method generateProof*(
|
|||||||
if g.userMessageLimit.isNone():
|
if g.userMessageLimit.isNone():
|
||||||
return err("user message limit is not set")
|
return err("user message limit is not set")
|
||||||
|
|
||||||
# Retrieve the cached Merkle proof for the membership index
|
let merkleProof = g.fetchMerkleProof()
|
||||||
let index = stuint(g.membershipIndex.get(), 256)
|
|
||||||
|
|
||||||
if not g.merkleProofsByIndex.hasKey(index):
|
|
||||||
try:
|
|
||||||
let merkleProofInvocation = g.wakuRlnContract.get().merkleProofElements(index)
|
|
||||||
let merkleProof = await merkleProofInvocation.call()
|
|
||||||
g.merkleProofsByIndex[index] = merkleProof
|
|
||||||
except CatchableError:
|
|
||||||
return err("Failed to fetch merkle proof: " & getCurrentExceptionMsg())
|
|
||||||
|
|
||||||
let merkleProof = g.merkleProofsByIndex[index]
|
|
||||||
if merkleProof.len == 0:
|
|
||||||
return err("Merkle proof not found")
|
|
||||||
|
|
||||||
# Prepare the witness
|
# Prepare the witness
|
||||||
let witness = Witness(
|
let witness = Witness(
|
||||||
@ -105,4 +100,4 @@ method generateProof*(
|
|||||||
shareY: shareY,
|
shareY: shareY,
|
||||||
nullifier: nullifier,
|
nullifier: nullifier,
|
||||||
)
|
)
|
||||||
return ok(output)
|
return ok(output)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user