Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add min accept depth #8

Merged
merged 2 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
25 changes: 11 additions & 14 deletions examples/channels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,27 @@ 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:
channels:
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
3 changes: 2 additions & 1 deletion examples/simple.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
policies:
-
-
min_accept_depth: 6
request:
channel_capacity:
min: 3_000_000
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main

Check warning on line 1 in main.go

View workflow job for this annotation

GitHub Actions / Lint

should have a package comment

import (
"context"
Expand Down Expand Up @@ -122,9 +122,15 @@
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
}
Expand Down
1 change: 1 addition & 0 deletions policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading