Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chain: match on new bitcoind v28.0 errors #948

Merged
merged 1 commit into from
Sep 12, 2024
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
9 changes: 9 additions & 0 deletions chain/bitcoind_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,15 @@ func (c *BitcoindClient) MapRPCErr(rpcErr error) error {
}
}

// Perhaps the backend is a newer version of bitcoind, try to match it
// against the v28.0 and later errors.
for btcdErr, matchedErr := range Bitcoind28ErrMap {
// Match it against btcd's error.
if matchErrStr(rpcErr, btcdErr) {
return matchedErr
}
}

// If not matched, return the original error wrapped.
return fmt.Errorf("%w: %v", ErrUndefined, rpcErr)
}
Expand Down
8 changes: 8 additions & 0 deletions chain/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,14 @@ func (r RPCErr) Error() string {
return "unknown error"
}

// Bitcoind28ErrMap contains error messages from bitcoind version v28.0 (and
// later) that are returned from the `testmempoolaccept` and are different than
// in previous versions.
var Bitcoind28ErrMap = map[string]error{
// https://github.com/bitcoin/bitcoin/pull/30212
"transaction outputs already in utxo set": ErrTxAlreadyConfirmed,
}

// BtcdErrMap takes the errors returned from btcd's `testmempoolaccept` and
// `sendrawtransaction` RPCs and map them to the errors defined above, which
// are results from calling either `testmempoolaccept` or `sendrawtransaction`
Expand Down