Skip to content

Commit

Permalink
Merge pull request #948 from guggero/bitcoind-28-error
Browse files Browse the repository at this point in the history
chain: match on new bitcoind v28.0 errors
  • Loading branch information
Roasbeef authored Sep 12, 2024
2 parents eaa60f1 + 1e4081b commit 738cd23
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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

0 comments on commit 738cd23

Please sign in to comment.