From dd02320eb1c201b309c484c96979c41309d2a61e Mon Sep 17 00:00:00 2001 From: aftermath2 Date: Thu, 21 Dec 2023 20:25:52 -0300 Subject: [PATCH 1/2] Fix channels example --- examples/channels.yml | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/examples/channels.yml b/examples/channels.yml index 557a8c4..c9dea08 100644 --- a/examples/channels.yml +++ b/examples/channels.yml @@ -7,11 +7,10 @@ policies: number: min: 10 max: 50 - policies: - request: - channel_capacity: - min: 1_000_000 - max: 3_000_000 + request: + channel_capacity: + min: 1_000_000 + max: 3_000_000 - conditions: node: @@ -19,18 +18,16 @@ policies: number: min: 50 max: 200 - policies: - request: - channel_capacity: - min: 3_000_000 - max: 10_000_000 + request: + channel_capacity: + min: 3_000_000 + max: 10_000_000 - conditions: node: channels: number: min: 200 - policies: - request: - channel_capacity: - min: 10_000_000 + request: + channel_capacity: + min: 10_000_000 From 0d9b3db7475f6d198f203a3037374f36c92e8b56 Mon Sep 17 00:00:00 2001 From: aftermath2 Date: Thu, 21 Dec 2023 20:36:21 -0300 Subject: [PATCH 2/2] Add min_accept_depth field --- README.md | 1 + examples/simple.yml | 3 ++- main.go | 8 +++++++- policy/policy.go | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 620ee51..24075d6 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ A policy would only be enforced if its conditions are satisfied, or if it has no | **accept_zero_conf_channels** | boolean | Whether to accept zero confirmation channels | | **zero_conf_list** | []string | List of nodes public keys whose zero conf requests will be accepted. Requires `accept_zero_conf_channels` to be `true` | | **reject_private_channels** | boolean | Whether private channels should be rejected | +| **min_accept_depth** | int | Number of confirmations required before considering the channel open | | **request** | [Request](#request) | Parameters related to the channel opening request | | **node** | [Node](#node) | Parameters related to the channel initiator | diff --git a/examples/simple.yml b/examples/simple.yml index f8cc775..5395ea2 100644 --- a/examples/simple.yml +++ b/examples/simple.yml @@ -1,5 +1,6 @@ policies: - - + - + min_accept_depth: 6 request: channel_capacity: min: 3_000_000 diff --git a/main.go b/main.go index 0362058..de4761f 100644 --- a/main.go +++ b/main.go @@ -122,9 +122,15 @@ func handleRequest( if err := policy.Evaluate(req, node, peer); err != nil { return resp, err } + + if policy.MinAcceptDepth != nil { + resp.MinAcceptDepth = *policy.MinAcceptDepth + } } - if req.WantsZeroConf { + if req.WantsZeroConf && len(config.Policies) != 0 { + // The initiator requested a zero conf channel and it was explicitly accepted, set the + // fields required to open it resp.ZeroConf = true resp.MinAcceptDepth = 0 } diff --git a/policy/policy.go b/policy/policy.go index a9dc2d6..6eef3c9 100644 --- a/policy/policy.go +++ b/policy/policy.go @@ -21,6 +21,7 @@ type Policy struct { RejectAll *bool `yaml:"reject_all,omitempty"` RejectPrivateChannels *bool `yaml:"reject_private_channels,omitempty"` AcceptZeroConfChannels *bool `yaml:"accept_zero_conf_channels,omitempty"` + MinAcceptDepth *uint32 `yaml:"min_accept_depth,omitempty"` } // Evaluate set of policies.