Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assertions/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ type Manager struct {
autoDeposit bool
autoAllowanceApproval bool
maxGetLogBlocks uint64
confirming *threadsafe.LruSet[protocol.AssertionHash]
confirmQueueMutex sync.Mutex
}

type assertionChainData struct {
Expand Down Expand Up @@ -248,6 +250,8 @@ func NewManager(
autoDeposit: true,
autoAllowanceApproval: true,
maxGetLogBlocks: 1000,
confirming: threadsafe.NewLruSet[protocol.AssertionHash](maxAssertions),
confirmQueueMutex: sync.Mutex{},
}
for _, o := range opts {
o(m)
Expand Down
3 changes: 2 additions & 1 deletion assertions/poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ func (m *Manager) PostAssertionBasedOnParent(
"postedExecutionState", fmt.Sprintf("%+v", newState),
"assertionHash", assertion.Id(),
)
m.observedCanonicalAssertions <- assertion.Id()

m.sendToConfirmationQueue(assertion.Id(), "PostAssertionBasedOnParent")
return option.Some(assertion), nil
}

Expand Down
27 changes: 25 additions & 2 deletions assertions/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (m *Manager) findCanonicalAssertionBranch(
cursor = assertion.AssertionHash
m.assertionChainData.latestAgreedAssertion = cursor
m.assertionChainData.canonicalAssertions[cursor] = assertion
m.observedCanonicalAssertions <- cursor
m.sendToConfirmationQueue(cursor, "findCanonicalAssertionBranch")
}
}
}
Expand Down Expand Up @@ -365,7 +365,7 @@ func (m *Manager) respondToAnyInvalidAssertions(
m.assertionChainData.canonicalAssertions[postedAssertionHash] = postedRival
m.submittedAssertions.Insert(postedAssertionHash)
m.submittedRivalsCount++
m.observedCanonicalAssertions <- postedAssertionHash
m.sendToConfirmationQueue(postedAssertionHash, "respondToAnyInvalidAssertions")
}
}
}
Expand Down Expand Up @@ -559,3 +559,26 @@ func (m *Manager) saveAssertionToDB(ctx context.Context, creationInfo *protocol.
Status: status.String(),
})
}

// Send assertion to confirmation queue
func (m *Manager) sendToConfirmationQueue(assertionHash protocol.AssertionHash, addedBy string) {
m.confirmQueueMutex.Lock()
defer m.confirmQueueMutex.Unlock()

// Check if assertion is already in confirmation queue
if m.confirming.Has(assertionHash) {
log.Debug("Assertion already in confirmation queue", "assertionHash", assertionHash, "addedBy", addedBy)
return // Already in confirmation queue, skip
}
log.Info("Sending assertion to confirmation queue", "assertionHash", assertionHash, "addedBy", addedBy)
// Mark as confirming
m.confirming.Insert(assertionHash)

// Send to confirmation queue
select {
case m.observedCanonicalAssertions <- assertionHash:
default:
m.confirming.Delete(assertionHash)
log.Warn("Failed to send assertion to confirmation queue: channel full", "assertionHash", assertionHash, "addedBy", addedBy)
}
}
2 changes: 2 additions & 0 deletions assertions/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func Test_findCanonicalAssertionBranch(t *testing.T) {
execProvider: provider,
chain: setup.Chains[0],
observedCanonicalAssertions: make(chan protocol.AssertionHash),
confirming: threadsafe.NewLruSet[protocol.AssertionHash](1000),
assertionChainData: &assertionChainData{
latestAgreedAssertion: numToAssertionHash(1),
canonicalAssertions: make(map[protocol.AssertionHash]*protocol.AssertionCreatedInfo),
Expand Down Expand Up @@ -267,6 +268,7 @@ func Test_respondToAnyInvalidAssertions(t *testing.T) {
manager := &Manager{
observedCanonicalAssertions: make(chan protocol.AssertionHash),
submittedAssertions: threadsafe.NewLruSet(1000, threadsafe.LruSetWithMetric[protocol.AssertionHash]("submittedAssertions")),
confirming: threadsafe.NewLruSet[protocol.AssertionHash](1000),
assertionChainData: &assertionChainData{
latestAgreedAssertion: numToAssertionHash(1),
canonicalAssertions: make(map[protocol.AssertionHash]*protocol.AssertionCreatedInfo),
Expand Down
Loading