-
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
feat: gRPC server #8
Changes from 12 commits
e73d7a1
07caec6
36e533e
7ddf4a2
93d77a4
c148faf
ba6fea0
8876f05
7d4206f
d7d3fd7
180ffd2
39edef3
9b42df7
939d712
a01a380
b369490
22fed16
34b6f52
4ccc16b
8953c7f
b934e2b
ce439ab
63816ab
32a59be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
|
||
# go build . will make a binary named gcosmos, which we never want to commit. | ||
gcosmos | ||
|
||
example-tx* |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,14 +38,42 @@ but sometimes a local patch makes more sense. | |
Begin running the updated siampp commands from the `gcosmos` directory. | ||
|
||
```bash | ||
go run . init moniker | ||
echo -n "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art" > $HOME/.simappv2/mnemonic.txt | ||
rm -rf ~/.simappv2/ | ||
go build -o gcosmos . | ||
|
||
go run . keys add val --recover --source $HOME/.simappv2/mnemonic.txt | ||
./gcosmos init moniker | ||
|
||
go run . genesis add-genesis-account val 1000000stake --keyring-backend=test | ||
go run . genesis gentx val 1000000stake --keyring-backend=test --chain-id=gcosmos | ||
go run . genesis collect-gentxs | ||
# cosmos1r5v5srda7xfth3hn2s26txvrcrntldjumt8mhl | ||
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. This comment is missing some words. 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. |
||
echo -n "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art" > example-mnemonic.txt | ||
|
||
go run . start | ||
./gcosmos keys add val --recover --source example-mnemonic.txt | ||
./gcosmos genesis add-genesis-account val 10000000stake --keyring-backend=test | ||
./gcosmos genesis gentx val 1000000stake --keyring-backend=test --chain-id=gcosmos | ||
./gcosmos genesis collect-gentxs | ||
|
||
# rm -rf ~/.simappv2/data/application.db/ | ||
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. Help the reader out -- why is this commented code here? Would they want to run it? If so, when? Same on the next section at L60. |
||
./gcosmos start --g-http-addr 127.0.0.1:26657 --g-grpc-addr 127.0.0.1:9092 | ||
``` | ||
|
||
# Interact | ||
```bash | ||
# go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest | ||
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. I would suggest Then we can just git-ignore 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. good call: |
||
|
||
grpcurl -plaintext localhost:9092 list | ||
grpcurl -plaintext localhost:9092 server.GordianGRPC/GetBlocksWatermark | ||
grpcurl -plaintext localhost:9092 server.GordianGRPC/GetValidators | ||
|
||
grpcurl -plaintext -d '{"address":"cosmos1r5v5srda7xfth3hn2s26txvrcrntldjumt8mhl","denom":"stake"}' localhost:9092 server.GordianGRPC/QueryAccountBalance | ||
``` | ||
|
||
# Transaction Testing | ||
```bash | ||
./gcosmos tx bank send val cosmos10r39fueph9fq7a6lgswu4zdsg8t3gxlqvvvyvn 1stake --chain-id=TODO:TEMPORARY_CHAIN_ID --generate-only > example-tx.json | ||
|
||
# TODO: get account number | ||
./gcosmos tx sign ./example-tx.json --offline --from=val --sequence=1 --account-number=1 --chain-id=TODO:TEMPORARY_CHAIN_ID --keyring-backend=test > example-tx-signed.json | ||
|
||
grpcurl -plaintext -emit-defaults -d '{"tx":"'$(cat example-tx-signed.json | base64 -w 0)'"}' localhost:9092 server.GordianGRPC/SimulateTransaction | ||
|
||
grpcurl -plaintext -emit-defaults -d '{"tx":"'$(cat example-tx-signed.json | base64 -w 0)'"}' localhost:9092 server.GordianGRPC/SubmitTransaction | ||
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.
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. Yes, migrated to use |
||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,10 @@ import ( | |
dht "github.com/libp2p/go-libp2p-kad-dht" | ||
libp2phost "github.com/libp2p/go-libp2p/core/host" | ||
libp2ppeer "github.com/libp2p/go-libp2p/core/peer" | ||
"github.com/rollchains/gordian/gcosmos/gserver/internal/ggrpc" | ||
"github.com/rollchains/gordian/gcosmos/gserver/internal/gsbd" | ||
"github.com/rollchains/gordian/gcosmos/gserver/internal/gsi" | ||
"github.com/rollchains/gordian/gcosmos/gserver/internal/txmanager" | ||
"github.com/rollchains/gordian/gcrypto" | ||
"github.com/rollchains/gordian/gdriver/gtxbuf" | ||
"github.com/rollchains/gordian/gwatchdog" | ||
|
@@ -72,10 +74,13 @@ type Component struct { | |
|
||
seedAddrs string | ||
|
||
httpLn net.Listener | ||
httpLn net.Listener | ||
grpcLn net.Listener | ||
|
||
ms tmstore.MirrorStore | ||
fs tmstore.FinalizationStore | ||
httpServer *gsi.HTTPServer | ||
grpcServer *ggrpc.GordianGRPC | ||
} | ||
|
||
// NewComponent returns a new server component | ||
|
@@ -157,7 +162,7 @@ func (c *Component) Start(ctx context.Context) error { | |
|
||
am := *(c.app.GetAppManager()) | ||
|
||
txm := gsi.TxManager{AppManager: am} | ||
txm := txmanager.TxManager{AppManager: am} | ||
txBuf := gtxbuf.New( | ||
ctx, c.log.With("d_sys", "tx_buffer"), | ||
txm.AddTx, txm.TxDeleterFunc, | ||
|
@@ -249,6 +254,25 @@ func (c *Component) Start(ctx context.Context) error { | |
Handler: e, | ||
}) | ||
|
||
if c.grpcLn != nil { | ||
// TODO; share this with the http server as a wrapper. | ||
// https://github.com/rollchains/gordian/pull/14 | ||
c.grpcServer = ggrpc.NewGordianGRPCServer(ctx, c.log.With("sys", "grpc"), ggrpc.GRPCServerConfig{ | ||
Listener: c.grpcLn, | ||
|
||
FinalizationStore: c.fs, | ||
MirrorStore: c.ms, | ||
|
||
CryptoRegistry: reg, | ||
|
||
// debug: | ||
TxCodec: c.txc, | ||
AppManager: am, | ||
TxBuf: txBuf, | ||
Codec: c.codec, | ||
}) | ||
} | ||
|
||
if c.httpLn != nil { | ||
c.httpServer = gsi.NewHTTPServer(ctx, c.log.With("sys", "http"), gsi.HTTPServerConfig{ | ||
Listener: c.httpLn, | ||
|
@@ -305,6 +329,20 @@ func (c *Component) Stop(_ context.Context) error { | |
c.httpServer.Wait() | ||
} | ||
} | ||
if c.grpcLn != nil { | ||
if err := c.grpcLn.Close(); err != nil { | ||
// If the GRPC server is closed directly, | ||
// it will close the underlying listener, | ||
// which will probably happen before our call to close the listener here. | ||
// Don't log if the error already indicated the network connection was closed. | ||
if !errors.Is(err, net.ErrClosed) { | ||
c.log.Warn("Error closing gRPC listener", "err", err) | ||
} | ||
} | ||
if c.grpcServer != nil { | ||
c.grpcServer.Wait() | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
|
@@ -324,15 +362,17 @@ func (c *Component) Init(app serverv2.AppI[transaction.Tx], v *viper.Viper, log | |
return fmt.Errorf("failed to listen for HTTP on %q: %w", httpAddr, err) | ||
} | ||
|
||
if f := v.GetString(httpAddrFileFlag); f != "" { | ||
// TODO: we should probably track this file and delete it on shutdown. | ||
addr := ln.Addr().String() + "\n" | ||
if err := os.WriteFile(f, []byte(addr), 0600); err != nil { | ||
return fmt.Errorf("failed to write HTTP address to file %q: %w", f, err) | ||
} | ||
c.httpLn = ln | ||
} | ||
|
||
// Maybe set up the GRPC server. | ||
if grpcAddrFlag := v.GetString(grpcAddrFlag); grpcAddrFlag != "" { | ||
ln, err := net.Listen("tcp", grpcAddrFlag) | ||
if err != nil { | ||
return fmt.Errorf("failed to listen for gRPC on %q: %w", grpcAddrFlag, err) | ||
} | ||
|
||
c.httpLn = ln | ||
c.grpcLn = ln | ||
} | ||
|
||
c.seedAddrs = v.GetString(seedAddrsFlag) | ||
|
@@ -406,6 +446,7 @@ func (c *Component) Init(app serverv2.AppI[transaction.Tx], v *viper.Viper, log | |
|
||
const ( | ||
httpAddrFlag = "g-http-addr" | ||
grpcAddrFlag = "g-grpc-addr" | ||
httpAddrFileFlag = "g-http-addr-file" | ||
|
||
seedAddrsFlag = "g-seed-addrs" | ||
|
@@ -415,6 +456,7 @@ func (c *Component) StartCmdFlags() *pflag.FlagSet { | |
flags := pflag.NewFlagSet("gserver", pflag.ExitOnError) | ||
|
||
flags.String(httpAddrFlag, "", "TCP address of Gordian's introspective HTTP server; if blank, server will not be started") | ||
flags.String(grpcAddrFlag, "", "GRPC address of Gordian's introspective GRPC server; if blank, server will not be started") | ||
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. This would be another TCP address (of the gRPC server), not a gRPC address.
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. |
||
flags.String(httpAddrFileFlag, "", "Write the actual Gordian HTTP listen address to the given file (useful for tests when configured to listen on :0)") | ||
|
||
flags.String(seedAddrsFlag, "", "Newline-separated multiaddrs to connect to; if omitted, relies on incoming connections to discover peers") | ||
|
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.
Include a comment noting what this is and why it's ignored.
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.
added context b369490