wathtower/blob+wtserver: support anchor sessions

This commit is contained in:
Conner Fromknecht 2020-11-25 15:04:00 -08:00
parent 069296c46c
commit 3856acce50
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
4 changed files with 35 additions and 3 deletions

View File

@ -138,8 +138,9 @@ func (t Type) String() string {
// supportedTypes is the set of all configurations known to be supported by the // supportedTypes is the set of all configurations known to be supported by the
// package. // package.
var supportedTypes = map[Type]struct{}{ var supportedTypes = map[Type]struct{}{
TypeAltruistCommit: {}, TypeAltruistCommit: {},
TypeRewardCommit: {}, TypeRewardCommit: {},
TypeAltruistAnchorCommit: {},
} }
// IsSupportedType returns true if the given type is supported by the package. // IsSupportedType returns true if the given type is supported by the package.

View File

@ -123,6 +123,12 @@ func TestSupportedTypes(t *testing.T) {
t.Fatalf("default type %s is not supported", blob.TypeAltruistCommit) t.Fatalf("default type %s is not supported", blob.TypeAltruistCommit)
} }
// Assert that the altruist anchor commit types are supported.
if !blob.IsSupportedType(blob.TypeAltruistAnchorCommit) {
t.Fatalf("default type %s is not supported",
blob.TypeAltruistAnchorCommit)
}
// Assert that all claimed supported types are actually supported. // Assert that all claimed supported types are actually supported.
for _, supType := range blob.SupportedTypes() { for _, supType := range blob.SupportedTypes() {
if blob.IsSupportedType(supType) { if blob.IsSupportedType(supType) {

View File

@ -96,7 +96,10 @@ type Server struct {
// sessions and send state updates. // sessions and send state updates.
func New(cfg *Config) (*Server, error) { func New(cfg *Config) (*Server, error) {
localInit := wtwire.NewInitMessage( localInit := wtwire.NewInitMessage(
lnwire.NewRawFeatureVector(wtwire.AltruistSessionsOptional), lnwire.NewRawFeatureVector(
wtwire.AltruistSessionsOptional,
wtwire.AnchorCommitOptional,
),
cfg.ChainHash, cfg.ChainHash,
) )

View File

@ -161,6 +161,28 @@ type createSessionTestCase struct {
} }
var createSessionTests = []createSessionTestCase{ var createSessionTests = []createSessionTestCase{
{
name: "duplicate session create altruist anchor commit",
initMsg: wtwire.NewInitMessage(
lnwire.NewRawFeatureVector(),
testnetChainHash,
),
createMsg: &wtwire.CreateSession{
BlobType: blob.TypeAltruistAnchorCommit,
MaxUpdates: 1000,
RewardBase: 0,
RewardRate: 0,
SweepFeeRate: 10000,
},
expReply: &wtwire.CreateSessionReply{
Code: wtwire.CodeOK,
Data: []byte{},
},
expDupReply: &wtwire.CreateSessionReply{
Code: wtwire.CodeOK,
Data: []byte{},
},
},
{ {
name: "duplicate session create", name: "duplicate session create",
initMsg: wtwire.NewInitMessage( initMsg: wtwire.NewInitMessage(