loop/loopdb/protocol_version.go
Andras Banki-Horvath 86db43a2cb loopdb: store protocol version alongside with swaps
This commit adds the protocol version to each stored swap. This will be
used to ensure that when swaps are resumed after a restart, they're
correctly handled given any breaking protocol changes.
2020-09-09 19:54:01 +02:00

76 lines
2.2 KiB
Go

package loopdb
import (
"math"
"github.com/lightninglabs/loop/looprpc"
)
// ProtocolVersion represents the protocol version (declared on rpc level) that
// the client declared to us.
type ProtocolVersion uint32
const (
// ProtocolVersionLegacy indicates that the client is a legacy version
// that did not report its protocol version.
ProtocolVersionLegacy ProtocolVersion = 0
// ProtocolVersionMultiLoopOut indicates that the client supports multi
// loop out.
ProtocolVersionMultiLoopOut ProtocolVersion = 1
// ProtocolVersionSegwitLoopIn indicates that the client supports segwit
// loop in.
ProtocolVersionSegwitLoopIn ProtocolVersion = 2
// ProtocolVersionPreimagePush indicates that the client will push loop
// out preimages to the sever to speed up claim.
ProtocolVersionPreimagePush ProtocolVersion = 3
// ProtocolVersionUserExpiryLoopOut indicates that the client will
// propose a cltv expiry height for loop out.
ProtocolVersionUserExpiryLoopOut ProtocolVersion = 4
// ProtocolVersionUnrecorded is set for swaps were created before we
// started saving protocol version with swaps.
ProtocolVersionUnrecorded ProtocolVersion = math.MaxUint32
// CurrentRpcProtocolVersion defines the version of the RPC protocol
// that is currently supported by the loop client.
CurrentRPCProtocolVersion = looprpc.ProtocolVersion_USER_EXPIRY_LOOP_OUT
// CurrentInteranlProtocolVersionInternal defines the RPC current
// protocol in the internal representation.
CurrentInternalProtocolVersion = ProtocolVersion(CurrentRPCProtocolVersion)
)
// Valid returns true if the value of the ProtocolVersion is valid.
func (p ProtocolVersion) Valid() bool {
return p <= CurrentInternalProtocolVersion
}
// String returns the string representation of a protocol version.
func (p ProtocolVersion) String() string {
switch p {
case ProtocolVersionUnrecorded:
return "Unrecorded"
case ProtocolVersionLegacy:
return "Legacy"
case ProtocolVersionMultiLoopOut:
return "Multi Loop Out"
case ProtocolVersionSegwitLoopIn:
return "Segwit Loop In"
case ProtocolVersionPreimagePush:
return "Preimage Push"
case ProtocolVersionUserExpiryLoopOut:
return "User Expiry Loop Out"
default:
return "Unknown"
}
}