-
Notifications
You must be signed in to change notification settings - Fork 3
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 Sensei #9
Open
joostjager
wants to merge
8
commits into
master
Choose a base branch
from
sensei
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Sensei #9
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fb6f2fb
remove unused interface elements
joostjager b7d2eef
add sensei
joostjager d627421
local proto gen
joostjager b5c8e19
use new sensei rpc fields
joostjager 9de8858
use num_known_edge_policies
joostjager 1bb21e2
fix channel balance
joostjager 9b36371
restore graph.yml
joostjager 1eb1bce
fix push amt
joostjager File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,269 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/bottlepay/lightning-benchmark/graphreader" | ||
"github.com/bottlepay/lightning-benchmark/sensei" | ||
"github.com/lightningnetwork/lnd/lnrpc" | ||
"github.com/lightningnetwork/lnd/routing/route" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
) | ||
|
||
type senseiConnection struct { | ||
conn *grpc.ClientConn | ||
pubKey route.Vertex | ||
alias string | ||
client sensei.NodeClient | ||
} | ||
|
||
func getSenseiConnection(alias string) (*senseiConnection, error) { | ||
logger := log.With("node", alias) | ||
|
||
rpcHost := fmt.Sprintf("node-%v:5401", alias) | ||
|
||
opts := []grpc.DialOption{ | ||
grpc.WithTransportCredentials(insecure.NewCredentials()), | ||
} | ||
|
||
logger.Infow("Attempting to connect to sensei") | ||
|
||
var adminConn *grpc.ClientConn | ||
err := tryFunc( | ||
func() error { | ||
var err error | ||
adminConn, err = grpc.Dial(rpcHost, opts...) | ||
if err != nil { | ||
return err | ||
} | ||
return err | ||
}, 60) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer adminConn.Close() | ||
|
||
logger.Infow("Creating node") | ||
|
||
adminClient := sensei.NewAdminClient(adminConn) | ||
|
||
createResp, err := adminClient.CreateAdmin(context.Background(), &sensei.CreateAdminRequest{ | ||
Username: "admin", | ||
Alias: alias, | ||
Passphrase: "secret", | ||
Start: true, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
pubkey, err := route.NewVertexFromStr(createResp.Pubkey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
time.Sleep(time.Second) | ||
|
||
mac := createResp.Macaroon | ||
|
||
cred, err := NewMacaroonCredential(mac) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
opts = append(opts, | ||
grpc.WithPerRPCCredentials(cred), | ||
) | ||
|
||
logger.Infow("Connecting with macaroon") | ||
|
||
var conn *grpc.ClientConn | ||
err = tryFunc( | ||
func() error { | ||
var err error | ||
conn, err = grpc.Dial(rpcHost, opts...) | ||
if err != nil { | ||
return err | ||
} | ||
return err | ||
}, 60) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &senseiConnection{ | ||
alias: alias, | ||
conn: conn, | ||
pubKey: pubkey, | ||
client: sensei.NewNodeClient(conn), | ||
}, nil | ||
} | ||
|
||
func (l *senseiConnection) PubKey() string { | ||
return l.pubKey.String() | ||
} | ||
|
||
func (l *senseiConnection) Close() { | ||
l.conn.Close() | ||
} | ||
|
||
func (l *senseiConnection) Connect(key, host string) error { | ||
_, err := l.client.ConnectPeer(context.Background(), &sensei.ConnectPeerRequest{ | ||
NodeConnectionString: fmt.Sprintf("%v@%v", key, host), | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (l *senseiConnection) NewAddress() (string, error) { | ||
resp, err := l.client.GetUnusedAddress( | ||
context.Background(), | ||
&sensei.GetUnusedAddressRequest{}, | ||
) | ||
if err != nil { | ||
return "", err | ||
} | ||
return resp.Address, nil | ||
} | ||
|
||
func (l *senseiConnection) OpenChannel(peerKey string, amtSat int64, | ||
pushAmtSat int64, private bool) error { | ||
|
||
var pushAmt uint64 = uint64(pushAmtSat) | ||
|
||
_, err := l.client.OpenChannels(context.Background(), &sensei.OpenChannelsRequest{ | ||
Requests: []*sensei.OpenChannelRequest{ | ||
{ | ||
AmountSats: uint64(amtSat), | ||
Public: !private, | ||
CounterpartyPubkey: peerKey, | ||
PushAmountMsats: &pushAmt, | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (l *senseiConnection) SetPolicy(chanPoint *lnrpc.ChannelPoint, | ||
policy *graphreader.PolicyData) error { | ||
|
||
// Not necessary for sender node. | ||
panic("not implemented") | ||
} | ||
|
||
func (l *senseiConnection) ActiveChannels() (int, error) { | ||
resp, err := l.client.ListChannels(context.Background(), &sensei.ListChannelsRequest{}) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
var active = 0 | ||
for _, ch := range resp.Channels { | ||
if ch.IsUsable { | ||
active++ | ||
} | ||
} | ||
|
||
return active, nil | ||
} | ||
|
||
func (l *senseiConnection) IsSynced(totalEdges, localChannels int) (bool, error) { | ||
resp, err := l.client.NetworkGraphInfo(context.Background(), &sensei.NetworkGraphInfoRequest{}) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
log.Debugw("Syncing", | ||
"edges", resp.NumKnownEdgePolicies, | ||
"totalEdges", totalEdges, | ||
"localChannels", localChannels) | ||
|
||
synced := resp.NumKnownEdgePolicies == uint64(totalEdges) | ||
|
||
return synced, nil | ||
} | ||
|
||
func (l *senseiConnection) AddInvoice(amtMsat int64) (string, error) { | ||
// Not necessary for sender node. | ||
panic("not implemented") | ||
} | ||
|
||
func (l *senseiConnection) SendPayment(invoice string, aliasMap map[string]string) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test is still a bit flakey, but I did get to the point where the test payments are started. Only it seems that they all execute in parallel? Is it possible to do a synchronous payment?
|
||
_, err := l.client.PayInvoice(context.Background(), &sensei.PayInvoiceRequest{ | ||
Invoice: invoice, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (l *senseiConnection) HasFunds() error { | ||
for { | ||
resp, err := l.client.GetBalance(context.Background(), | ||
&sensei.GetBalanceRequest{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if resp.OnchainBalanceSats > 0 { | ||
return nil | ||
} | ||
|
||
time.Sleep(time.Second) | ||
} | ||
} | ||
|
||
func (l *senseiConnection) Restart() (nodeInterface, error) { | ||
// Not needed for sensei to get synced correctly - hopefully. | ||
panic("not implemented") | ||
} | ||
|
||
func (l *senseiConnection) GetChannelBalance() (int, error) { | ||
resp, err := l.client.GetBalance(context.Background(), | ||
&sensei.GetBalanceRequest{}) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return int(resp.ChannelBalanceMsats) / 1000, nil | ||
} | ||
|
||
// MacaroonCredential wraps a macaroon to implement the | ||
// credentials.PerRPCCredentials interface. | ||
type MacaroonCredential struct { | ||
mac string | ||
} | ||
|
||
// RequireTransportSecurity implements the PerRPCCredentials interface. | ||
func (m MacaroonCredential) RequireTransportSecurity() bool { | ||
return false | ||
} | ||
|
||
// GetRequestMetadata implements the PerRPCCredentials interface. This method | ||
// is required in order to pass the wrapped macaroon into the gRPC context. | ||
// With this, the macaroon will be available within the request handling scope | ||
// of the ultimate gRPC server implementation. | ||
func (m MacaroonCredential) GetRequestMetadata(ctx context.Context, | ||
uri ...string) (map[string]string, error) { | ||
|
||
md := make(map[string]string) | ||
md["macaroon"] = m.mac | ||
return md, nil | ||
} | ||
|
||
// NewMacaroonCredential returns a copy of the passed macaroon wrapped in a | ||
// MacaroonCredential struct which implements PerRPCCredentials. | ||
func NewMacaroonCredential(mac string) (MacaroonCredential, error) { | ||
ms := MacaroonCredential{mac: mac} | ||
|
||
return ms, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johncantrell97 I might now be getting into a different class of hurdles:
This should be reproducible by running
./run.sh sensei
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well the first panic indicates incorrect bitcoind rpc configuration.
the second one is saying that it tried to connect a block where the header.prev_blockhash did not match the best known blockhash. so for some reason it missed blocks.
it's odd that it even got that far or are these separate runs where you fixed rpc info?
I'd try blowing up your sensei db and try a fresh run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the first one I think is when it starts a bit early and fails because bitcoind isn't running yet. Docker-compose will then restart, so yes, this could be considered separate runs. I believe it's unrelated to the second error.
The sensei db will be created new every time I run
run.sh
. But I did find out that the error isn't always happening. Appears to be timing-dependent. Perhaps because a whole bunch of blocks are generated in quick succession, something bad happens occasionally?