contractcourt: fix concurrent access to resolved

This commit makes `resolved` an atomic bool to avoid data race. This
field is now defined in `contractResolverKit` to avoid code duplication.
This commit is contained in:
yyforyongyu committed 2024-12-20 17:54:06 +08:00
1 parent 47722292c5
commit 4f5ccb8650
11 files changed
+111 -129

No files matched your search

+3 -14
View File
@@ -24,9 +24,6 @@ type anchorResolver struct {
// anchor is the outpoint on the commitment transaction.
anchor wire.OutPoint
// resolved reflects if the contract has been fully resolved or not.
resolved bool
// broadcastHeight is the height that the original contract was
// broadcast to the main-chain at. We'll use this value to bound any
// historical queries to the chain for spends/confirmations.
@@ -89,7 +86,7 @@ func (c *anchorResolver) ResolverKey() []byte {
// NOTE: Part of the ContractResolver interface.
func (c *anchorResolver) Resolve() (ContractResolver, error) {
// If we're already resolved, then we can exit early.
if c.resolved {
if c.IsResolved() {
c.log.Errorf("already resolved")
return nil, nil
}
@@ -139,7 +136,7 @@ func (c *anchorResolver) Resolve() (ContractResolver, error) {
)
c.reportLock.Unlock()
c.resolved = true
c.markResolved()
return nil, c.PutResolverReport(nil, report)
}
@@ -154,14 +151,6 @@ func (c *anchorResolver) Stop() {
close(c.quit)
}
// IsResolved returns true if the stored state in the resolve is fully
// resolved. In this case the target output can be forgotten.
//
// NOTE: Part of the ContractResolver interface.
func (c *anchorResolver) IsResolved() bool {
return c.resolved
}
// SupplementState allows the user of a ContractResolver to supplement it with
// state required for the proper resolution of a contract.
//
@@ -198,7 +187,7 @@ func (c *anchorResolver) Launch() error {
c.launched = true
// If we're already resolved, then we can exit early.
if c.resolved {
if c.IsResolved() {
c.log.Errorf("already resolved")
return nil
}