multi: ensure link is always torn down due to db failures, add exponential back off for sql-kvdb failures (#7927)
* lnwallet: fix log output msg The log message is off by one. * htlcswitch: fail channel when revoking it fails. When the revocation of a channel state fails after receiving a new CommitmentSigned msg we have to fail the channel otherwise we continue with an unclean state. * docs: update release-docs * htlcswitch: tear down connection if revocation processing fails If we couldn't revoke due to a DB error, then we want to also tear down the connection, as we don't want the other party to continue to send updates. That may lead to de-sync'd state an eventual force close. Otherwise, the database might be able to recover come the next reconnection attempt. * kvdb: use sql.LevelSerializable for all backends In this commit, we modify the default isolation level to be `sql.LevelSerializable. This is the strictness isolation type for postgres. For sqlite, there's only ever a single writer, so this doesn't apply directly. * kvdb/sqlbase: add randomized exponential backoff for serialization failures In this commit, we add randomized exponential backoff for serialization failures. For postgres, we''ll his this any time a transaction set fails to be linearized. For sqlite, we'll his this if we have many writers trying to grab the write lock at time same time, manifesting as a `SQLITE_BUSY` error code. As is, we'll retry up to 10 times, waiting a minimum of 50 miliseconds between each attempt, up to 5 seconds without any delay at all. For sqlite, this is also bounded by the busy timeout set, which applies on top of this retry logic (block for busy timeout seconds, then apply this back off logic). * docs/release-notes: add entry for sqlite/postgres tx retry --------- Co-authored-by: ziggie <ziggie1984@protonmail.com>
This commit is contained in:
1 parent
eb0d8af645
commit
01c64712a3
7 files changed
+173
-19
No files matched your search
+26
-2
@@ -1943,6 +1943,25 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
|
||||
l.channel.RevokeCurrentCommitment()
|
||||
if err != nil {
|
||||
l.log.Errorf("unable to revoke commitment: %v", err)
|
||||
|
||||
// We need to fail the channel in case revoking our
|
||||
// local commitment does not succeed. We might have
|
||||
// already advanced our channel state which would lead
|
||||
// us to proceed with an unclean state.
|
||||
//
|
||||
// NOTE: We do not trigger a force close because this
|
||||
// could resolve itself in case our db was just busy
|
||||
// not accepting new transactions.
|
||||
l.fail(
|
||||
LinkFailureError{
|
||||
code: ErrInternalError,
|
||||
Warning: true,
|
||||
FailureAction: LinkFailureDisconnect,
|
||||
},
|
||||
"ChannelPoint(%v): unable to accept new "+
|
||||
"commitment: %v",
|
||||
l.channel.ChannelPoint(), err,
|
||||
)
|
||||
return
|
||||
}
|
||||
l.cfg.Peer.SendMessage(false, nextRevocation)
|
||||
@@ -2007,8 +2026,13 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
|
||||
ReceiveRevocation(msg)
|
||||
if err != nil {
|
||||
// TODO(halseth): force close?
|
||||
l.fail(LinkFailureError{code: ErrInvalidRevocation},
|
||||
"unable to accept revocation: %v", err)
|
||||
l.fail(
|
||||
LinkFailureError{
|
||||
code: ErrInvalidRevocation,
|
||||
FailureAction: LinkFailureDisconnect,
|
||||
},
|
||||
"unable to accept revocation: %v", err,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,10 @@ type LinkFailureError struct {
|
||||
// the channel should not be attempted loaded again.
|
||||
PermanentFailure bool
|
||||
|
||||
// Warning denotes if this is a non-terminal error that doesn't warrant
|
||||
// failing the channel all together.
|
||||
Warning bool
|
||||
|
||||
// SendData is a byte slice that will be sent to the peer. If nil a
|
||||
// generic error will be sent.
|
||||
SendData []byte
|
||||
|
||||
Reference in new issue
Block a user