From 8459573c07b7e139395609596eeb1c1d881c88d3 Mon Sep 17 00:00:00 2001 From: zramsay Date: Sat, 14 Mar 2020 13:11:44 -0400 Subject: [PATCH 01/61] use go get for install --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c860d1a..128a7be 100644 --- a/README.md +++ b/README.md @@ -31,11 +31,8 @@ sudo apt-get install libssl-dev libuv1-dev cmake make curl g++ Clone the Gecko repository: ```sh -cd $GOPATH -mkdir -p src/github.com/ava-labs -cd src/github.com/ava-labs -git clone https://github.com/ava-labs/gecko.git -cd gecko +go get github.com/ava-labs/gecko +cd $GOPATH/src/github.com/ava-labs/gecko ``` #### Building the Gecko Executable From e71a91d3bd356a2f070d474223e06ecfe2c38532 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Thu, 9 Apr 2020 00:42:44 +0100 Subject: [PATCH 02/61] vms: Facter service setup out of AVM service tests --- vms/avm/service_test.go | 84 ++++++++--------------------------------- 1 file changed, 16 insertions(+), 68 deletions(-) diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index 9221634..64dcdd8 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -12,11 +12,11 @@ import ( "github.com/ava-labs/gecko/vms/secp256k1fx" ) -func TestGetAssetDescription(t *testing.T) { +func setup(t *testing.T) ([]byte, *VM, *Service) { genesisBytes := BuildGenesisTest(t) + // TODO: Could this initialization be replaced by a call to GenesisVM() ctx.Lock.Lock() - defer ctx.Lock.Unlock() vm := &VM{} err := vm.Initialize( @@ -32,16 +32,21 @@ func TestGetAssetDescription(t *testing.T) { if err != nil { t.Fatal(err) } + s := &Service{vm: vm} + return genesisBytes, vm, s +} + +func TestGetAssetDescription(t *testing.T) { + genesisBytes, vm, s := setup(t) + defer ctx.Lock.Unlock() defer vm.Shutdown() genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t) avaAssetID := genesisTx.ID() - s := Service{vm: vm} - reply := GetAssetDescriptionReply{} - err = s.GetAssetDescription(nil, &GetAssetDescriptionArgs{ + err := s.GetAssetDescription(nil, &GetAssetDescriptionArgs{ AssetID: avaAssetID.String(), }, &reply) if err != nil { @@ -57,35 +62,16 @@ func TestGetAssetDescription(t *testing.T) { } func TestGetBalance(t *testing.T) { - genesisBytes := BuildGenesisTest(t) - - ctx.Lock.Lock() + genesisBytes, vm, s := setup(t) defer ctx.Lock.Unlock() - - vm := &VM{} - err := vm.Initialize( - ctx, - memdb.New(), - genesisBytes, - make(chan common.Message, 1), - []*common.Fx{&common.Fx{ - ID: ids.Empty, - Fx: &secp256k1fx.Fx{}, - }}, - ) - if err != nil { - t.Fatal(err) - } defer vm.Shutdown() genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t) avaAssetID := genesisTx.ID() - s := Service{vm: vm} - reply := GetBalanceReply{} - err = s.GetBalance(nil, &GetBalanceArgs{ + err := s.GetBalance(nil, &GetBalanceArgs{ Address: vm.Format(keys[0].PublicKey().Address().Bytes()), AssetID: avaAssetID.String(), }, &reply) @@ -99,31 +85,12 @@ func TestGetBalance(t *testing.T) { } func TestCreateFixedCapAsset(t *testing.T) { - genesisBytes := BuildGenesisTest(t) - - ctx.Lock.Lock() + _, vm, s := setup(t) defer ctx.Lock.Unlock() - - vm := &VM{} - err := vm.Initialize( - ctx, - memdb.New(), - genesisBytes, - make(chan common.Message, 1), - []*common.Fx{&common.Fx{ - ID: ids.Empty, - Fx: &secp256k1fx.Fx{}, - }}, - ) - if err != nil { - t.Fatal(err) - } defer vm.Shutdown() - s := Service{vm: vm} - reply := CreateFixedCapAssetReply{} - err = s.CreateFixedCapAsset(nil, &CreateFixedCapAssetArgs{ + err := s.CreateFixedCapAsset(nil, &CreateFixedCapAssetArgs{ Name: "test asset", Symbol: "test", Denomination: 1, @@ -142,31 +109,12 @@ func TestCreateFixedCapAsset(t *testing.T) { } func TestCreateVariableCapAsset(t *testing.T) { - genesisBytes := BuildGenesisTest(t) - - ctx.Lock.Lock() + _, vm, s := setup(t) defer ctx.Lock.Unlock() - - vm := &VM{} - err := vm.Initialize( - ctx, - memdb.New(), - genesisBytes, - make(chan common.Message, 1), - []*common.Fx{&common.Fx{ - ID: ids.Empty, - Fx: &secp256k1fx.Fx{}, - }}, - ) - if err != nil { - t.Fatal(err) - } defer vm.Shutdown() - s := Service{vm: vm} - reply := CreateVariableCapAssetReply{} - err = s.CreateVariableCapAsset(nil, &CreateVariableCapAssetArgs{ + err := s.CreateVariableCapAsset(nil, &CreateVariableCapAssetArgs{ Name: "test asset", Symbol: "test", MinterSets: []Owners{ From 1161455b37b1e8ce44ba92c293529c05fe80bb97 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Thu, 9 Apr 2020 00:55:21 +0100 Subject: [PATCH 03/61] vms: Factor NewTx() out of TestIssueTx() --- vms/avm/vm_test.go | 97 ++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 46 deletions(-) diff --git a/vms/avm/vm_test.go b/vms/avm/vm_test.go index e629c4b..4bc4a0f 100644 --- a/vms/avm/vm_test.go +++ b/vms/avm/vm_test.go @@ -191,6 +191,56 @@ func GenesisVM(t *testing.T) *VM { return vm } +func NewTx(t *testing.T, genesisBytes []byte, vm *VM) *Tx { + genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t) + + newTx := &Tx{UnsignedTx: &BaseTx{ + NetID: networkID, + BCID: chainID, + Ins: []*ava.TransferableInput{&ava.TransferableInput{ + UTXOID: ava.UTXOID{ + TxID: genesisTx.ID(), + OutputIndex: 1, + }, + Asset: ava.Asset{ID: genesisTx.ID()}, + In: &secp256k1fx.TransferInput{ + Amt: 50000, + Input: secp256k1fx.Input{ + SigIndices: []uint32{ + 0, + }, + }, + }, + }}, + }} + + unsignedBytes, err := vm.codec.Marshal(&newTx.UnsignedTx) + if err != nil { + t.Fatal(err) + } + + key := keys[0] + sig, err := key.Sign(unsignedBytes) + if err != nil { + t.Fatal(err) + } + fixedSig := [crypto.SECP256K1RSigLen]byte{} + copy(fixedSig[:], sig) + + newTx.Creds = append(newTx.Creds, &secp256k1fx.Credential{ + Sigs: [][crypto.SECP256K1RSigLen]byte{ + fixedSig, + }, + }) + + b, err := vm.codec.Marshal(newTx) + if err != nil { + t.Fatal(err) + } + newTx.Initialize(b) + return newTx +} + func TestTxSerialization(t *testing.T) { expected := []byte{ // txID: @@ -448,52 +498,7 @@ func TestIssueTx(t *testing.T) { } vm.batchTimeout = 0 - genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t) - - newTx := &Tx{UnsignedTx: &BaseTx{ - NetID: networkID, - BCID: chainID, - Ins: []*ava.TransferableInput{&ava.TransferableInput{ - UTXOID: ava.UTXOID{ - TxID: genesisTx.ID(), - OutputIndex: 1, - }, - Asset: ava.Asset{ID: genesisTx.ID()}, - In: &secp256k1fx.TransferInput{ - Amt: 50000, - Input: secp256k1fx.Input{ - SigIndices: []uint32{ - 0, - }, - }, - }, - }}, - }} - - unsignedBytes, err := vm.codec.Marshal(&newTx.UnsignedTx) - if err != nil { - t.Fatal(err) - } - - key := keys[0] - sig, err := key.Sign(unsignedBytes) - if err != nil { - t.Fatal(err) - } - fixedSig := [crypto.SECP256K1RSigLen]byte{} - copy(fixedSig[:], sig) - - newTx.Creds = append(newTx.Creds, &secp256k1fx.Credential{ - Sigs: [][crypto.SECP256K1RSigLen]byte{ - fixedSig, - }, - }) - - b, err := vm.codec.Marshal(newTx) - if err != nil { - t.Fatal(err) - } - newTx.Initialize(b) + newTx := NewTx(t, genesisBytes, vm) txID, err := vm.IssueTx(newTx.Bytes(), nil) if err != nil { From 70e571b77c83782690fb2bcbeda86faaa3c82dcb Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Thu, 9 Apr 2020 00:57:43 +0100 Subject: [PATCH 04/61] vms: add test for Service.IssueTx() --- vms/avm/service_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index 64dcdd8..71f5b8e 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -9,6 +9,7 @@ import ( "github.com/ava-labs/gecko/database/memdb" "github.com/ava-labs/gecko/ids" "github.com/ava-labs/gecko/snow/engine/common" + "github.com/ava-labs/gecko/utils/formatting" "github.com/ava-labs/gecko/vms/secp256k1fx" ) @@ -36,6 +37,31 @@ func setup(t *testing.T) ([]byte, *VM, *Service) { return genesisBytes, vm, s } +func TestServiceIssueTx(t *testing.T) { + genesisBytes, vm, s := setup(t) + // TODO: Does this need to be here? Or can the lock be released once the + // VM is initilized? + defer ctx.Lock.Unlock() + defer vm.Shutdown() + + txArgs := &IssueTxArgs{} + txReply := &IssueTxReply{} + err := s.IssueTx(nil, txArgs, txReply) + if err == nil { + t.Fatal("Expected empty transaction to return an error") + } + + tx := NewTx(t, genesisBytes, vm) + txArgs.Tx = formatting.CB58{Bytes: tx.Bytes()} + txReply = &IssueTxReply{} + if err := s.IssueTx(nil, txArgs, txReply); err != nil { + t.Fatal(err) + } + if !txReply.TxID.Equals(tx.ID()) { + t.Fatalf("Expected %q, got %q", txReply.TxID, tx.ID()) + } +} + func TestGetAssetDescription(t *testing.T) { genesisBytes, vm, s := setup(t) defer ctx.Lock.Unlock() From 208195bf34319b0264b45d781e3468e73bc7f7ec Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Thu, 9 Apr 2020 00:58:30 +0100 Subject: [PATCH 05/61] vms: add test for Service.GetTxStatus() --- vms/avm/service_test.go | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index 71f5b8e..098e168 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -6,6 +6,8 @@ package avm import ( "testing" + "github.com/ava-labs/gecko/snow/choices" + "github.com/ava-labs/gecko/database/memdb" "github.com/ava-labs/gecko/ids" "github.com/ava-labs/gecko/snow/engine/common" @@ -62,6 +64,47 @@ func TestServiceIssueTx(t *testing.T) { } } +func TestServiceGetTxStatus(t *testing.T) { + genesisBytes, vm, s := setup(t) + defer ctx.Lock.Unlock() + defer vm.Shutdown() + + statusArgs := &GetTxStatusArgs{} + statusReply := &GetTxStatusReply{} + if err := s.GetTxStatus(nil, statusArgs, statusReply); err == nil { + t.Fatal("Expected empty transaction to return an error") + } + + tx := NewTx(t, genesisBytes, vm) + statusArgs.TxID = tx.ID() + statusReply = &GetTxStatusReply{} + if err := s.GetTxStatus(nil, statusArgs, statusReply); err != nil { + t.Fatal(err) + } + if expected := choices.Unknown; expected != statusReply.Status { + t.Fatalf( + "Expected an unsubmitted tx to have status %q, got %q", + expected.String(), statusReply.Status.String(), + ) + } + + txArgs := &IssueTxArgs{Tx: formatting.CB58{Bytes: tx.Bytes()}} + txReply := &IssueTxReply{} + if err := s.IssueTx(nil, txArgs, txReply); err != nil { + t.Fatal(err) + } + statusReply = &GetTxStatusReply{} + if err := s.GetTxStatus(nil, statusArgs, statusReply); err != nil { + t.Fatal(err) + } + if expected := choices.Processing; expected != statusReply.Status { + t.Fatalf( + "Expected a submitted tx to have status %q, got %q", + expected.String(), statusReply.Status.String(), + ) + } +} + func TestGetAssetDescription(t *testing.T) { genesisBytes, vm, s := setup(t) defer ctx.Lock.Unlock() From 795d3ffd3cb7712c4f114781666584a661790ca9 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 13 Apr 2020 09:28:54 +0100 Subject: [PATCH 06/61] vms: Standardise on GenesisVM() in test suite, where possible Note that GenesisVM now leaves the Context locked. It is the resposibility of the caller to unlock it. --- vms/avm/base_tx_test.go | 176 ++------------------------------- vms/avm/prefixed_state_test.go | 9 +- vms/avm/service_test.go | 4 +- vms/avm/state_test.go | 12 ++- vms/avm/vm_test.go | 71 ++----------- 5 files changed, 34 insertions(+), 238 deletions(-) diff --git a/vms/avm/base_tx_test.go b/vms/avm/base_tx_test.go index 9033b3b..0bff657 100644 --- a/vms/avm/base_tx_test.go +++ b/vms/avm/base_tx_test.go @@ -743,29 +743,9 @@ func TestBaseTxSyntacticVerifyUninitialized(t *testing.T) { } func TestBaseTxSemanticVerify(t *testing.T) { - genesisBytes := BuildGenesisTest(t) - - issuer := make(chan common.Message, 1) - - ctx.Lock.Lock() + genesisBytes, _, vm := GenesisVM(t) defer ctx.Lock.Unlock() - vm := &VM{} - err := vm.Initialize( - ctx, - memdb.New(), - genesisBytes, - issuer, - []*common.Fx{&common.Fx{ - ID: ids.Empty, - Fx: &secp256k1fx.Fx{}, - }}, - ) - if err != nil { - t.Fatal(err) - } - vm.batchTimeout = 0 - genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t) tx := &Tx{UnsignedTx: &BaseTx{ @@ -827,29 +807,9 @@ func TestBaseTxSemanticVerify(t *testing.T) { } func TestBaseTxSemanticVerifyUnknownFx(t *testing.T) { - genesisBytes := BuildGenesisTest(t) - - issuer := make(chan common.Message, 1) - - ctx.Lock.Lock() + genesisBytes, _, vm := GenesisVM(t) defer ctx.Lock.Unlock() - vm := &VM{} - err := vm.Initialize( - ctx, - memdb.New(), - genesisBytes, - issuer, - []*common.Fx{&common.Fx{ - ID: ids.Empty, - Fx: &secp256k1fx.Fx{}, - }}, - ) - if err != nil { - t.Fatal(err) - } - vm.batchTimeout = 0 - vm.codec.RegisterType(&ava.TestVerifiable{}) genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t) @@ -896,29 +856,9 @@ func TestBaseTxSemanticVerifyUnknownFx(t *testing.T) { } func TestBaseTxSemanticVerifyWrongAssetID(t *testing.T) { - genesisBytes := BuildGenesisTest(t) - - issuer := make(chan common.Message, 1) - - ctx.Lock.Lock() + genesisBytes, _, vm := GenesisVM(t) defer ctx.Lock.Unlock() - vm := &VM{} - err := vm.Initialize( - ctx, - memdb.New(), - genesisBytes, - issuer, - []*common.Fx{&common.Fx{ - ID: ids.Empty, - Fx: &secp256k1fx.Fx{}, - }}, - ) - if err != nil { - t.Fatal(err) - } - vm.batchTimeout = 0 - vm.codec.RegisterType(&ava.TestVerifiable{}) genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t) @@ -1073,29 +1013,9 @@ func TestBaseTxSemanticVerifyUnauthorizedFx(t *testing.T) { } func TestBaseTxSemanticVerifyInvalidSignature(t *testing.T) { - genesisBytes := BuildGenesisTest(t) - - issuer := make(chan common.Message, 1) - - ctx.Lock.Lock() + genesisBytes, _, vm := GenesisVM(t) defer ctx.Lock.Unlock() - vm := &VM{} - err := vm.Initialize( - ctx, - memdb.New(), - genesisBytes, - issuer, - []*common.Fx{&common.Fx{ - ID: ids.Empty, - Fx: &secp256k1fx.Fx{}, - }}, - ) - if err != nil { - t.Fatal(err) - } - vm.batchTimeout = 0 - genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t) tx := &Tx{UnsignedTx: &BaseTx{ @@ -1144,29 +1064,9 @@ func TestBaseTxSemanticVerifyInvalidSignature(t *testing.T) { } func TestBaseTxSemanticVerifyMissingUTXO(t *testing.T) { - genesisBytes := BuildGenesisTest(t) - - issuer := make(chan common.Message, 1) - - ctx.Lock.Lock() + genesisBytes, _, vm := GenesisVM(t) defer ctx.Lock.Unlock() - vm := &VM{} - err := vm.Initialize( - ctx, - memdb.New(), - genesisBytes, - issuer, - []*common.Fx{&common.Fx{ - ID: ids.Empty, - Fx: &secp256k1fx.Fx{}, - }}, - ) - if err != nil { - t.Fatal(err) - } - vm.batchTimeout = 0 - genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t) tx := &Tx{UnsignedTx: &BaseTx{ @@ -1228,29 +1128,9 @@ func TestBaseTxSemanticVerifyMissingUTXO(t *testing.T) { } func TestBaseTxSemanticVerifyInvalidUTXO(t *testing.T) { - genesisBytes := BuildGenesisTest(t) - - issuer := make(chan common.Message, 1) - - ctx.Lock.Lock() + genesisBytes, _, vm := GenesisVM(t) defer ctx.Lock.Unlock() - vm := &VM{} - err := vm.Initialize( - ctx, - memdb.New(), - genesisBytes, - issuer, - []*common.Fx{&common.Fx{ - ID: ids.Empty, - Fx: &secp256k1fx.Fx{}, - }}, - ) - if err != nil { - t.Fatal(err) - } - vm.batchTimeout = 0 - genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t) tx := &Tx{UnsignedTx: &BaseTx{ @@ -1312,27 +1192,7 @@ func TestBaseTxSemanticVerifyInvalidUTXO(t *testing.T) { } func TestBaseTxSemanticVerifyPendingInvalidUTXO(t *testing.T) { - genesisBytes := BuildGenesisTest(t) - - issuer := make(chan common.Message, 1) - - ctx.Lock.Lock() - - vm := &VM{} - err := vm.Initialize( - ctx, - memdb.New(), - genesisBytes, - issuer, - []*common.Fx{&common.Fx{ - ID: ids.Empty, - Fx: &secp256k1fx.Fx{}, - }}, - ) - if err != nil { - t.Fatal(err) - } - vm.batchTimeout = 0 + genesisBytes, issuer, vm := GenesisVM(t) genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t) @@ -1463,27 +1323,7 @@ func TestBaseTxSemanticVerifyPendingInvalidUTXO(t *testing.T) { } func TestBaseTxSemanticVerifyPendingWrongAssetID(t *testing.T) { - genesisBytes := BuildGenesisTest(t) - - issuer := make(chan common.Message, 1) - - ctx.Lock.Lock() - - vm := &VM{} - err := vm.Initialize( - ctx, - memdb.New(), - genesisBytes, - issuer, - []*common.Fx{&common.Fx{ - ID: ids.Empty, - Fx: &secp256k1fx.Fx{}, - }}, - ) - if err != nil { - t.Fatal(err) - } - vm.batchTimeout = 0 + genesisBytes, issuer, vm := GenesisVM(t) genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t) diff --git a/vms/avm/prefixed_state_test.go b/vms/avm/prefixed_state_test.go index 8a69f91..1d790d5 100644 --- a/vms/avm/prefixed_state_test.go +++ b/vms/avm/prefixed_state_test.go @@ -16,7 +16,8 @@ import ( ) func TestPrefixedSetsAndGets(t *testing.T) { - vm := GenesisVM(t) + _, _, vm := GenesisVM(t) + ctx.Lock.Unlock() state := vm.state vm.codec.RegisterType(&ava.TestVerifiable{}) @@ -110,7 +111,8 @@ func TestPrefixedSetsAndGets(t *testing.T) { } func TestPrefixedFundingNoAddresses(t *testing.T) { - vm := GenesisVM(t) + _, _, vm := GenesisVM(t) + ctx.Lock.Unlock() state := vm.state vm.codec.RegisterType(&ava.TestVerifiable{}) @@ -133,7 +135,8 @@ func TestPrefixedFundingNoAddresses(t *testing.T) { } func TestPrefixedFundingAddresses(t *testing.T) { - vm := GenesisVM(t) + _, _, vm := GenesisVM(t) + ctx.Lock.Unlock() state := vm.state vm.codec.RegisterType(&testAddressable{}) diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index 098e168..f889fe3 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -18,9 +18,11 @@ import ( func setup(t *testing.T) ([]byte, *VM, *Service) { genesisBytes := BuildGenesisTest(t) - // TODO: Could this initialization be replaced by a call to GenesisVM() ctx.Lock.Lock() + // This is VM initilialzation is very silimar to that done by GenesisVM(). + // However that function also sets vm.batchTimeout = 0, which causes the + // tests in this module to deadlock. vm := &VM{} err := vm.Initialize( ctx, diff --git a/vms/avm/state_test.go b/vms/avm/state_test.go index 212fc18..aac77c1 100644 --- a/vms/avm/state_test.go +++ b/vms/avm/state_test.go @@ -15,7 +15,8 @@ import ( ) func TestStateIDs(t *testing.T) { - vm := GenesisVM(t) + _, _, vm := GenesisVM(t) + ctx.Lock.Unlock() state := vm.state.state id0 := ids.NewID([32]byte{0xff, 0}) @@ -124,7 +125,8 @@ func TestStateIDs(t *testing.T) { } func TestStateStatuses(t *testing.T) { - vm := GenesisVM(t) + _, _, vm := GenesisVM(t) + ctx.Lock.Unlock() state := vm.state.state if _, err := state.Status(ids.Empty); err == nil { @@ -172,7 +174,8 @@ func TestStateStatuses(t *testing.T) { } func TestStateUTXOs(t *testing.T) { - vm := GenesisVM(t) + _, _, vm := GenesisVM(t) + ctx.Lock.Unlock() state := vm.state.state vm.codec.RegisterType(&ava.TestVerifiable{}) @@ -242,7 +245,8 @@ func TestStateUTXOs(t *testing.T) { } func TestStateTXs(t *testing.T) { - vm := GenesisVM(t) + _, _, vm := GenesisVM(t) + ctx.Lock.Unlock() state := vm.state.state vm.codec.RegisterType(&ava.TestTransferable{}) diff --git a/vms/avm/vm_test.go b/vms/avm/vm_test.go index 4bc4a0f..3cd7642 100644 --- a/vms/avm/vm_test.go +++ b/vms/avm/vm_test.go @@ -166,18 +166,20 @@ func BuildGenesisTest(t *testing.T) []byte { return reply.Bytes.Bytes } -func GenesisVM(t *testing.T) *VM { +func GenesisVM(t *testing.T) ([]byte, chan common.Message, *VM) { genesisBytes := BuildGenesisTest(t) + // NB: this lock is intentionally left locked when this function returns. + // The caller of this function is responsible for unlocking. ctx.Lock.Lock() - defer ctx.Lock.Unlock() + issuer := make(chan common.Message, 1) vm := &VM{} err := vm.Initialize( ctx, memdb.New(), genesisBytes, - make(chan common.Message, 1), + issuer, []*common.Fx{&common.Fx{ ID: ids.Empty, Fx: &secp256k1fx.Fx{}, @@ -188,7 +190,7 @@ func GenesisVM(t *testing.T) *VM { } vm.batchTimeout = 0 - return vm + return genesisBytes, issuer, vm } func NewTx(t *testing.T, genesisBytes []byte, vm *VM) *Tx { @@ -477,26 +479,7 @@ type testTxBytes struct{ unsignedBytes []byte } func (tx *testTxBytes) UnsignedBytes() []byte { return tx.unsignedBytes } func TestIssueTx(t *testing.T) { - genesisBytes := BuildGenesisTest(t) - - issuer := make(chan common.Message, 1) - - ctx.Lock.Lock() - vm := &VM{} - err := vm.Initialize( - ctx, - memdb.New(), - genesisBytes, - issuer, - []*common.Fx{&common.Fx{ - ID: ids.Empty, - Fx: &secp256k1fx.Fx{}, - }}, - ) - if err != nil { - t.Fatal(err) - } - vm.batchTimeout = 0 + genesisBytes, issuer, vm := GenesisVM(t) newTx := NewTx(t, genesisBytes, vm) @@ -520,24 +503,7 @@ func TestIssueTx(t *testing.T) { } func TestGenesisGetUTXOs(t *testing.T) { - genesisBytes := BuildGenesisTest(t) - - ctx.Lock.Lock() - vm := &VM{} - err := vm.Initialize( - ctx, - memdb.New(), - genesisBytes, - make(chan common.Message, 1), - []*common.Fx{&common.Fx{ - ID: ids.Empty, - Fx: &secp256k1fx.Fx{}, - }}, - ) - if err != nil { - t.Fatal(err) - } - vm.batchTimeout = 0 + _, _, vm := GenesisVM(t) shortAddr := keys[0].PublicKey().Address() addr := ids.NewID(hashing.ComputeHash256Array(shortAddr.Bytes())) @@ -559,26 +525,7 @@ func TestGenesisGetUTXOs(t *testing.T) { // Test issuing a transaction that consumes a currently pending UTXO. The // transaction should be issued successfully. func TestIssueDependentTx(t *testing.T) { - genesisBytes := BuildGenesisTest(t) - - issuer := make(chan common.Message, 1) - - ctx.Lock.Lock() - vm := &VM{} - err := vm.Initialize( - ctx, - memdb.New(), - genesisBytes, - issuer, - []*common.Fx{&common.Fx{ - ID: ids.Empty, - Fx: &secp256k1fx.Fx{}, - }}, - ) - if err != nil { - t.Fatal(err) - } - vm.batchTimeout = 0 + genesisBytes, issuer, vm := GenesisVM(t) genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t) From b8e1094309aa2f45e572dbe32d5ecb5785348b22 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 13 Apr 2020 09:40:12 +0100 Subject: [PATCH 07/61] vms: Add tests for avm.Service.GetUTXOs --- vms/avm/service_test.go | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index f889fe3..918f35e 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -4,6 +4,7 @@ package avm import ( + "fmt" "testing" "github.com/ava-labs/gecko/snow/choices" @@ -107,6 +108,84 @@ func TestServiceGetTxStatus(t *testing.T) { } } +func TestServiceGetUTXOsInvalidAddress(t *testing.T) { + _, vm, s := setup(t) + defer ctx.Lock.Unlock() + defer vm.Shutdown() + + addr0 := keys[0].PublicKey().Address() + tests := []struct { + label string + args *GetUTXOsArgs + }{ + {"[", &GetUTXOsArgs{[]string{""}}}, + {"[-]", &GetUTXOsArgs{[]string{"-"}}}, + {"[foo]", &GetUTXOsArgs{[]string{"foo"}}}, + {"[foo-bar]", &GetUTXOsArgs{[]string{"foo-bar"}}}, + {"[]", &GetUTXOsArgs{[]string{ctx.ChainID.String()}}}, + {"[-]", &GetUTXOsArgs{[]string{fmt.Sprintf("%s-", ctx.ChainID.String())}}}, + {"[-]", &GetUTXOsArgs{[]string{fmt.Sprintf("%s-%s", ids.NewID([32]byte{42}).String(), addr0.String())}}}, + } + for _, tt := range tests { + t.Run(tt.label, func(t *testing.T) { + utxosReply := &GetUTXOsReply{} + if err := s.GetUTXOs(nil, tt.args, utxosReply); err == nil { + t.Error(err) + } + }) + } +} + +func TestServiceGetUTXOs(t *testing.T) { + _, vm, s := setup(t) + defer ctx.Lock.Unlock() + defer vm.Shutdown() + + addr0 := keys[0].PublicKey().Address() + tests := []struct { + label string + args *GetUTXOsArgs + count int + }{ + { + "Empty", + &GetUTXOsArgs{}, + 0, + }, { + "[-]", + &GetUTXOsArgs{[]string{ + // TODO: Should GetUTXOs() raise an error for this? The address portion is + // longer than addr0.String() + fmt.Sprintf("%s-%s", ctx.ChainID.String(), ids.NewID([32]byte{42}).String()), + }}, + 0, + }, { + "[-]", + &GetUTXOsArgs{[]string{ + fmt.Sprintf("%s-%s", ctx.ChainID.String(), addr0.String()), + }}, + 7, + }, { + "[-,-]", + &GetUTXOsArgs{[]string{ + fmt.Sprintf("%s-%s", ctx.ChainID.String(), addr0.String()), + fmt.Sprintf("%s-%s", ctx.ChainID.String(), addr0.String()), + }}, + 7, + }, + } + for _, tt := range tests { + t.Run(tt.label, func(t *testing.T) { + utxosReply := &GetUTXOsReply{} + if err := s.GetUTXOs(nil, tt.args, utxosReply); err != nil { + t.Error(err) + } else if tt.count != len(utxosReply.UTXOs) { + t.Errorf("Expected %d utxos, got %#v", tt.count, len(utxosReply.UTXOs)) + } + }) + } +} + func TestGetAssetDescription(t *testing.T) { genesisBytes, vm, s := setup(t) defer ctx.Lock.Unlock() From 163eec2dd3c15f9bb8149082001a05a88ea9a89c Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 13 Apr 2020 10:59:47 +0100 Subject: [PATCH 08/61] vms: Standardize on setupCodec() in avm tests --- vms/avm/base_tx_test.go | 145 ++++---------------------------------- vms/avm/import_tx_test.go | 14 +--- vms/avm/tx_test.go | 42 +++-------- vms/avm/vm_test.go | 27 +------ 4 files changed, 23 insertions(+), 205 deletions(-) diff --git a/vms/avm/base_tx_test.go b/vms/avm/base_tx_test.go index 9033b3b..1d3233f 100644 --- a/vms/avm/base_tx_test.go +++ b/vms/avm/base_tx_test.go @@ -13,7 +13,6 @@ import ( "github.com/ava-labs/gecko/snow/engine/common" "github.com/ava-labs/gecko/utils/crypto" "github.com/ava-labs/gecko/vms/components/ava" - "github.com/ava-labs/gecko/vms/components/codec" "github.com/ava-labs/gecko/vms/secp256k1fx" ) @@ -108,17 +107,7 @@ func TestBaseTxSerialization(t *testing.T) { }}, }} - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) + c := setupCodec() b, err := c.Marshal(&tx.UnsignedTx) if err != nil { @@ -185,17 +174,7 @@ func TestBaseTxGetters(t *testing.T) { } func TestBaseTxSyntacticVerify(t *testing.T) { - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) + c := setupCodec() tx := &BaseTx{ NetID: networkID, @@ -237,17 +216,7 @@ func TestBaseTxSyntacticVerify(t *testing.T) { } func TestBaseTxSyntacticVerifyNil(t *testing.T) { - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) + c := setupCodec() tx := (*BaseTx)(nil) if err := tx.SyntacticVerify(ctx, c, 0); err == nil { @@ -256,17 +225,7 @@ func TestBaseTxSyntacticVerifyNil(t *testing.T) { } func TestBaseTxSyntacticVerifyWrongNetworkID(t *testing.T) { - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) + c := setupCodec() tx := &BaseTx{ NetID: 0, @@ -308,17 +267,7 @@ func TestBaseTxSyntacticVerifyWrongNetworkID(t *testing.T) { } func TestBaseTxSyntacticVerifyWrongChainID(t *testing.T) { - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) + c := setupCodec() tx := &BaseTx{ NetID: networkID, @@ -360,17 +309,7 @@ func TestBaseTxSyntacticVerifyWrongChainID(t *testing.T) { } func TestBaseTxSyntacticVerifyInvalidOutput(t *testing.T) { - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) + c := setupCodec() tx := &BaseTx{ NetID: networkID, @@ -403,17 +342,7 @@ func TestBaseTxSyntacticVerifyInvalidOutput(t *testing.T) { } func TestBaseTxSyntacticVerifyUnsortedOutputs(t *testing.T) { - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) + c := setupCodec() tx := &BaseTx{ NetID: networkID, @@ -469,17 +398,7 @@ func TestBaseTxSyntacticVerifyUnsortedOutputs(t *testing.T) { } func TestBaseTxSyntacticVerifyInvalidInput(t *testing.T) { - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) + c := setupCodec() tx := &BaseTx{ NetID: networkID, @@ -504,17 +423,7 @@ func TestBaseTxSyntacticVerifyInvalidInput(t *testing.T) { } func TestBaseTxSyntacticVerifyInputOverflow(t *testing.T) { - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) + c := setupCodec() tx := &BaseTx{ NetID: networkID, @@ -576,17 +485,7 @@ func TestBaseTxSyntacticVerifyInputOverflow(t *testing.T) { } func TestBaseTxSyntacticVerifyOutputOverflow(t *testing.T) { - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) + c := setupCodec() tx := &BaseTx{ NetID: networkID, @@ -640,17 +539,7 @@ func TestBaseTxSyntacticVerifyOutputOverflow(t *testing.T) { } func TestBaseTxSyntacticVerifyInsufficientFunds(t *testing.T) { - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) + c := setupCodec() tx := &BaseTx{ NetID: networkID, @@ -692,17 +581,7 @@ func TestBaseTxSyntacticVerifyInsufficientFunds(t *testing.T) { } func TestBaseTxSyntacticVerifyUninitialized(t *testing.T) { - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) + c := setupCodec() tx := &BaseTx{ NetID: networkID, diff --git a/vms/avm/import_tx_test.go b/vms/avm/import_tx_test.go index eb8f25b..e0f5605 100644 --- a/vms/avm/import_tx_test.go +++ b/vms/avm/import_tx_test.go @@ -15,7 +15,6 @@ import ( "github.com/ava-labs/gecko/utils/crypto" "github.com/ava-labs/gecko/utils/logging" "github.com/ava-labs/gecko/vms/components/ava" - "github.com/ava-labs/gecko/vms/components/codec" "github.com/ava-labs/gecko/vms/secp256k1fx" ) @@ -89,18 +88,7 @@ func TestImportTxSerialization(t *testing.T) { }}, }} - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) - + c := setupCodec() b, err := c.Marshal(&tx.UnsignedTx) if err != nil { t.Fatal(err) diff --git a/vms/avm/tx_test.go b/vms/avm/tx_test.go index a26f595..5ec1671 100644 --- a/vms/avm/tx_test.go +++ b/vms/avm/tx_test.go @@ -22,7 +22,7 @@ func TestTxNil(t *testing.T) { } } -func TestTxEmpty(t *testing.T) { +func setupCodec() codec.Codec { c := codec.NewDefault() c.RegisterType(&BaseTx{}) c.RegisterType(&CreateAssetTx{}) @@ -34,7 +34,11 @@ func TestTxEmpty(t *testing.T) { c.RegisterType(&secp256k1fx.TransferOutput{}) c.RegisterType(&secp256k1fx.MintOperation{}) c.RegisterType(&secp256k1fx.Credential{}) + return c +} +func TestTxEmpty(t *testing.T) { + c := setupCodec() tx := &Tx{} if err := tx.SyntacticVerify(ctx, c, 1); err == nil { t.Fatalf("Should have errored due to nil tx") @@ -42,17 +46,7 @@ func TestTxEmpty(t *testing.T) { } func TestTxInvalidCredential(t *testing.T) { - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) + c := setupCodec() c.RegisterType(&ava.TestVerifiable{}) tx := &Tx{ @@ -90,17 +84,7 @@ func TestTxInvalidCredential(t *testing.T) { } func TestTxInvalidUnsignedTx(t *testing.T) { - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) + c := setupCodec() c.RegisterType(&ava.TestVerifiable{}) tx := &Tx{ @@ -158,17 +142,7 @@ func TestTxInvalidUnsignedTx(t *testing.T) { } func TestTxInvalidNumberOfCredentials(t *testing.T) { - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) + c := setupCodec() c.RegisterType(&ava.TestVerifiable{}) tx := &Tx{ diff --git a/vms/avm/vm_test.go b/vms/avm/vm_test.go index e629c4b..ef54a18 100644 --- a/vms/avm/vm_test.go +++ b/vms/avm/vm_test.go @@ -16,7 +16,6 @@ import ( "github.com/ava-labs/gecko/utils/hashing" "github.com/ava-labs/gecko/utils/units" "github.com/ava-labs/gecko/vms/components/ava" - "github.com/ava-labs/gecko/vms/components/codec" "github.com/ava-labs/gecko/vms/components/verify" "github.com/ava-labs/gecko/vms/nftfx" "github.com/ava-labs/gecko/vms/propertyfx" @@ -50,18 +49,7 @@ func init() { } func GetFirstTxFromGenesisTest(genesisBytes []byte, t *testing.T) *Tx { - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) - + c := setupCodec() genesis := Genesis{} if err := c.Unmarshal(genesisBytes, &genesis); err != nil { t.Fatal(err) @@ -338,18 +326,7 @@ func TestTxSerialization(t *testing.T) { }) } - c := codec.NewDefault() - c.RegisterType(&BaseTx{}) - c.RegisterType(&CreateAssetTx{}) - c.RegisterType(&OperationTx{}) - c.RegisterType(&ImportTx{}) - c.RegisterType(&ExportTx{}) - c.RegisterType(&secp256k1fx.TransferInput{}) - c.RegisterType(&secp256k1fx.MintOutput{}) - c.RegisterType(&secp256k1fx.TransferOutput{}) - c.RegisterType(&secp256k1fx.MintOperation{}) - c.RegisterType(&secp256k1fx.Credential{}) - + c := setupCodec() b, err := c.Marshal(tx) if err != nil { t.Fatal(err) From cd23540e4e9a9bdafc476db592535a1fb075cfff Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 13 Apr 2020 11:19:21 +0100 Subject: [PATCH 09/61] vms: Add test of avm.Tx.SemanticVerify with nil transaction --- vms/avm/tx_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vms/avm/tx_test.go b/vms/avm/tx_test.go index a26f595..2767468 100644 --- a/vms/avm/tx_test.go +++ b/vms/avm/tx_test.go @@ -20,6 +20,9 @@ func TestTxNil(t *testing.T) { if err := tx.SyntacticVerify(ctx, c, 1); err == nil { t.Fatalf("Should have errored due to nil tx") } + if err := tx.SemanticVerify(nil, nil); err == nil { + t.Fatalf("Should have errored due to nil tx") + } } func TestTxEmpty(t *testing.T) { From 689177e113f6ca0c9109a1673fa2c8165f8879ac Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Wed, 15 Apr 2020 20:27:12 +0100 Subject: [PATCH 10/61] vms: Reword timeout warning, include a link to discussion --- vms/avm/service_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index 918f35e..710974c 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -21,9 +21,10 @@ func setup(t *testing.T) ([]byte, *VM, *Service) { ctx.Lock.Lock() - // This is VM initilialzation is very silimar to that done by GenesisVM(). - // However that function also sets vm.batchTimeout = 0, which causes the - // tests in this module to deadlock. + // This VM initilialzation is very similar to that done by GenesisVM(). + // However replacing the body of this function, with a call to GenesisVM + // causes a timeout while executing the test suite. + // https://github.com/ava-labs/gecko/pull/59#pullrequestreview-392478636 vm := &VM{} err := vm.Initialize( ctx, From 0933380c995ef7d2a18a64053332b04328a8bd28 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Wed, 15 Apr 2020 16:54:39 -0400 Subject: [PATCH 11/61] Correctly configure the max message size for non-staking networks --- node/node.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/node/node.go b/node/node.go index caded55..4f4309d 100644 --- a/node/node.go +++ b/node/node.go @@ -151,9 +151,10 @@ func (n *Node) initNetlib() error { // Create peer network config, may have tls enabled peerConfig := salticidae.NewPeerNetworkConfig() + msgConfig := peerConfig.AsMsgNetworkConfig() + msgConfig.MaxMsgSize(maxMessageSize) + if n.Config.EnableStaking { - msgConfig := peerConfig.AsMsgNetworkConfig() - msgConfig.MaxMsgSize(maxMessageSize) msgConfig.EnableTLS(true) msgConfig.TLSKeyFile(n.Config.StakingKeyFile) msgConfig.TLSCertFile(n.Config.StakingCertFile) From ad1e8b75e523608f117ebf7aeaa2bd22bfc1c6be Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Wed, 15 Apr 2020 17:49:08 -0400 Subject: [PATCH 12/61] Increased the reconnect timeout to ease network upgrades --- networking/handshake_handlers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/networking/handshake_handlers.go b/networking/handshake_handlers.go index e037781..de6bb9c 100644 --- a/networking/handshake_handlers.go +++ b/networking/handshake_handlers.go @@ -79,7 +79,7 @@ const ( GetVersionTimeout = 2 * time.Second // ReconnectTimeout is the amount of time to wait to reconnect to a staker // before giving up - ReconnectTimeout = 1 * time.Minute + ReconnectTimeout = 10 * time.Minute ) // Manager is the struct that will be accessed on event calls From 42baab288130884fae51827d4206ed5fd4d7ef84 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 16 Apr 2020 11:39:20 -0400 Subject: [PATCH 13/61] Move Geth to a plugin connected at runtime * removed coreth + geth dependency for the C-chain, still have nat + crypto dependencies * Added first past of nat traversal * Removed go-eth dependency for secp256k1 * renamed db files to not repeat the package title * Added rpcdb, untested * Added rpcdb tests * removed defer from loop * cleaned up tests * Started working on the rpc chain VM * First pass of vm plugin support * Added http over grpc * added beta support for http handlers * updated vms for the rpcvms * Added error returns for factories * Added EVM back to the genesis * Added the EVM factory * Added EVM aliasing, fixed nil pointer bugs during shutdown * Added plugin folder * Removed plugins folder, add default params for the plugin dir * Added http RPC test * Added cascade evm genesis * Removed debug line * removed more debug lines * Cleaned up import statement * Changed default plugin dir to ./plugins * build evm plugin auto in the build script --- .gitignore | 6 + Dockerfile | 4 - chains/manager.go | 15 +- database/encdb/{encdb.go => db.go} | 0 database/encdb/{encdb_test.go => db_test.go} | 0 database/leveldb/{leveldb.go => db.go} | 0 .../leveldb/{leveldb_test.go => db_test.go} | 0 database/memdb/{memdb.go => db.go} | 0 database/memdb/{memdb_test.go => db_test.go} | 0 database/mockdb/{mockdb.go => db.go} | 0 .../mockdb/{mockdb_test.go => db_test.go} | 0 database/nodb/{nodb.go => db.go} | 0 database/prefixdb/{prefixdb.go => db.go} | 0 .../prefixdb/{prefixdb_test.go => db_test.go} | 0 database/rpcdb/db_client.go | 268 +++ database/rpcdb/db_server.go | 143 ++ database/rpcdb/db_test.go | 51 + database/rpcdb/proto/db.pb.go | 1526 +++++++++++++++++ database/rpcdb/proto/db.proto | 108 ++ database/test_database.go | 101 ++ database/versiondb/{versiondb.go => db.go} | 0 .../{versiondb_test.go => db_test.go} | 0 genesis/aliases.go | 7 +- genesis/config.go | 197 ++- genesis/genesis.go | 60 +- genesis/genesis_test.go | 7 +- main/main.go | 25 +- main/params.go | 10 +- nat/mapper.go | 143 ++ nat/no_router.go | 28 + nat/pmp.go | 71 + nat/router.go | 65 + nat/upnp.go | 253 +++ node/config.go | 8 +- node/node.go | 7 +- scripts/build.sh | 17 +- scripts/build_image.sh | 2 - snow/engine/common/http_handler.go | 2 +- snow/engine/common/message.go | 2 +- utils/crypto/crypto_benchmark_test.go | 2 +- utils/crypto/secp256k1.go | 149 -- .../secp256k1_recover_benchmark_test.go | 48 - utils/crypto/secp256k1r.go | 98 +- utils/crypto/secp256k1r_test.go | 23 + vms/avm/factory.go | 4 +- vms/avm/vm.go | 4 + vms/components/core/snowman_vm.go | 4 + vms/evm/block.go | 75 - vms/evm/database.go | 66 - vms/evm/factory.go | 19 - vms/evm/service.go | 122 -- vms/evm/static_service.go | 22 - vms/evm/static_service_test.go | 64 - vms/evm/vm.go | 498 ------ vms/evm/vm_genesis_parse_test.go | 32 - vms/manager.go | 11 +- vms/nftfx/factory.go | 2 +- vms/nftfx/factory_test.go | 4 +- vms/platformvm/factory.go | 4 +- vms/platformvm/vm.go | 4 + vms/propertyfx/factory.go | 2 +- vms/propertyfx/factory_test.go | 4 +- vms/rpcchainvm/factory.go | 54 + vms/rpcchainvm/ghttp/http_client.go | 64 + vms/rpcchainvm/ghttp/http_server.go | 62 + vms/rpcchainvm/ghttp/http_test.go | 96 ++ vms/rpcchainvm/ghttp/proto/http.pb.go | 297 ++++ vms/rpcchainvm/ghttp/proto/http.proto | 24 + vms/rpcchainvm/messenger/messenger_client.go | 27 + vms/rpcchainvm/messenger/messenger_server.go | 37 + .../messenger/proto/messenger.pb.go | 194 +++ .../messenger/proto/messenger.proto | 12 + vms/rpcchainvm/proto/vm.pb.go | 1433 ++++++++++++++++ vms/rpcchainvm/proto/vm.proto | 100 ++ vms/rpcchainvm/vm.go | 50 + vms/rpcchainvm/vm_client.go | 336 ++++ vms/rpcchainvm/vm_server.go | 240 +++ vms/secp256k1fx/factory.go | 2 +- vms/secp256k1fx/factory_test.go | 4 +- vms/spchainvm/factory.go | 2 +- vms/spchainvm/vm.go | 4 + vms/spdagvm/factory.go | 4 +- vms/spdagvm/vm.go | 4 + vms/timestampvm/factory.go | 2 +- 84 files changed, 6179 insertions(+), 1256 deletions(-) rename database/encdb/{encdb.go => db.go} (100%) rename database/encdb/{encdb_test.go => db_test.go} (100%) rename database/leveldb/{leveldb.go => db.go} (100%) rename database/leveldb/{leveldb_test.go => db_test.go} (100%) rename database/memdb/{memdb.go => db.go} (100%) rename database/memdb/{memdb_test.go => db_test.go} (100%) rename database/mockdb/{mockdb.go => db.go} (100%) rename database/mockdb/{mockdb_test.go => db_test.go} (100%) rename database/nodb/{nodb.go => db.go} (100%) rename database/prefixdb/{prefixdb.go => db.go} (100%) rename database/prefixdb/{prefixdb_test.go => db_test.go} (100%) create mode 100644 database/rpcdb/db_client.go create mode 100644 database/rpcdb/db_server.go create mode 100644 database/rpcdb/db_test.go create mode 100644 database/rpcdb/proto/db.pb.go create mode 100644 database/rpcdb/proto/db.proto rename database/versiondb/{versiondb.go => db.go} (100%) rename database/versiondb/{versiondb_test.go => db_test.go} (100%) create mode 100644 nat/mapper.go create mode 100644 nat/no_router.go create mode 100644 nat/pmp.go create mode 100644 nat/router.go create mode 100644 nat/upnp.go delete mode 100644 utils/crypto/secp256k1.go delete mode 100644 utils/crypto/secp256k1_recover_benchmark_test.go delete mode 100644 vms/evm/block.go delete mode 100644 vms/evm/database.go delete mode 100644 vms/evm/factory.go delete mode 100644 vms/evm/service.go delete mode 100644 vms/evm/static_service.go delete mode 100644 vms/evm/static_service_test.go delete mode 100644 vms/evm/vm.go delete mode 100644 vms/evm/vm_genesis_parse_test.go create mode 100644 vms/rpcchainvm/factory.go create mode 100644 vms/rpcchainvm/ghttp/http_client.go create mode 100644 vms/rpcchainvm/ghttp/http_server.go create mode 100644 vms/rpcchainvm/ghttp/http_test.go create mode 100644 vms/rpcchainvm/ghttp/proto/http.pb.go create mode 100644 vms/rpcchainvm/ghttp/proto/http.proto create mode 100644 vms/rpcchainvm/messenger/messenger_client.go create mode 100644 vms/rpcchainvm/messenger/messenger_server.go create mode 100644 vms/rpcchainvm/messenger/proto/messenger.pb.go create mode 100644 vms/rpcchainvm/messenger/proto/messenger.proto create mode 100644 vms/rpcchainvm/proto/vm.pb.go create mode 100644 vms/rpcchainvm/proto/vm.proto create mode 100644 vms/rpcchainvm/vm.go create mode 100644 vms/rpcchainvm/vm_client.go create mode 100644 vms/rpcchainvm/vm_server.go diff --git a/.gitignore b/.gitignore index 6b1e28c..f8a87c9 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ awscpu *.ava db* + *cpu[0-9]* *mem[0-9]* *lock[0-9]* @@ -46,3 +47,8 @@ bin/ build/ keys/staker.* + +!*.go +!*.proto + +plugins/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b24a23f..13ef1e7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,10 +6,6 @@ RUN apt-get update && apt-get install -y libssl-dev libuv1-dev curl cmake RUN mkdir -p /go/src/github.com/ava-labs -# Because downloading ethereum takes long it is done separately, so that the docker -# layer, when cached can be re-used -RUN go get -t -v github.com/ava-labs/go-ethereum - WORKDIR $GOPATH/src/github.com/ava-labs/ COPY . gecko diff --git a/chains/manager.go b/chains/manager.go index aef8064..3f7d48d 100644 --- a/chains/manager.go +++ b/chains/manager.go @@ -214,7 +214,12 @@ func (m *manager) ForceCreateChain(chain ChainParameters) { } // Create the chain - vm := vmFactory.New() + vm, err := vmFactory.New() + if err != nil { + m.log.Error("error while creating vm: %s", err) + return + } + // TODO: Shutdown VM if an error occurs fxs := make([]*common.Fx, len(chain.FxAliases)) for i, fxAlias := range chain.FxAliases { @@ -231,10 +236,16 @@ func (m *manager) ForceCreateChain(chain ChainParameters) { return } + fx, err := fxFactory.New() + if err != nil { + m.log.Error("error while creating fx: %s", err) + return + } + // Create the fx fxs[i] = &common.Fx{ ID: fxID, - Fx: fxFactory.New(), + Fx: fx, } } diff --git a/database/encdb/encdb.go b/database/encdb/db.go similarity index 100% rename from database/encdb/encdb.go rename to database/encdb/db.go diff --git a/database/encdb/encdb_test.go b/database/encdb/db_test.go similarity index 100% rename from database/encdb/encdb_test.go rename to database/encdb/db_test.go diff --git a/database/leveldb/leveldb.go b/database/leveldb/db.go similarity index 100% rename from database/leveldb/leveldb.go rename to database/leveldb/db.go diff --git a/database/leveldb/leveldb_test.go b/database/leveldb/db_test.go similarity index 100% rename from database/leveldb/leveldb_test.go rename to database/leveldb/db_test.go diff --git a/database/memdb/memdb.go b/database/memdb/db.go similarity index 100% rename from database/memdb/memdb.go rename to database/memdb/db.go diff --git a/database/memdb/memdb_test.go b/database/memdb/db_test.go similarity index 100% rename from database/memdb/memdb_test.go rename to database/memdb/db_test.go diff --git a/database/mockdb/mockdb.go b/database/mockdb/db.go similarity index 100% rename from database/mockdb/mockdb.go rename to database/mockdb/db.go diff --git a/database/mockdb/mockdb_test.go b/database/mockdb/db_test.go similarity index 100% rename from database/mockdb/mockdb_test.go rename to database/mockdb/db_test.go diff --git a/database/nodb/nodb.go b/database/nodb/db.go similarity index 100% rename from database/nodb/nodb.go rename to database/nodb/db.go diff --git a/database/prefixdb/prefixdb.go b/database/prefixdb/db.go similarity index 100% rename from database/prefixdb/prefixdb.go rename to database/prefixdb/db.go diff --git a/database/prefixdb/prefixdb_test.go b/database/prefixdb/db_test.go similarity index 100% rename from database/prefixdb/prefixdb_test.go rename to database/prefixdb/db_test.go diff --git a/database/rpcdb/db_client.go b/database/rpcdb/db_client.go new file mode 100644 index 0000000..8d23049 --- /dev/null +++ b/database/rpcdb/db_client.go @@ -0,0 +1,268 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package rpcdb + +import ( + "fmt" + + "golang.org/x/net/context" + + "github.com/ava-labs/gecko/database" + "github.com/ava-labs/gecko/database/nodb" + "github.com/ava-labs/gecko/database/rpcdb/proto" +) + +var ( + errClosed = fmt.Sprintf("rpc error: code = Unknown desc = %s", database.ErrClosed) + errNotFound = fmt.Sprintf("rpc error: code = Unknown desc = %s", database.ErrNotFound) +) + +// DatabaseClient is an implementation of database that talks over RPC. +type DatabaseClient struct{ client proto.DatabaseClient } + +// NewClient returns a database instance connected to a remote database instance +func NewClient(client proto.DatabaseClient) *DatabaseClient { + return &DatabaseClient{client: client} +} + +// Has returns false, nil +func (db *DatabaseClient) Has(key []byte) (bool, error) { + resp, err := db.client.Has(context.Background(), &proto.HasRequest{ + Key: key, + }) + if err != nil { + return false, updateError(err) + } + return resp.Has, nil +} + +// Get returns nil, error +func (db *DatabaseClient) Get(key []byte) ([]byte, error) { + resp, err := db.client.Get(context.Background(), &proto.GetRequest{ + Key: key, + }) + if err != nil { + return nil, updateError(err) + } + return resp.Value, nil +} + +// Put returns nil +func (db *DatabaseClient) Put(key, value []byte) error { + _, err := db.client.Put(context.Background(), &proto.PutRequest{ + Key: key, + Value: value, + }) + return updateError(err) +} + +// Delete returns nil +func (db *DatabaseClient) Delete(key []byte) error { + _, err := db.client.Delete(context.Background(), &proto.DeleteRequest{ + Key: key, + }) + return updateError(err) +} + +// NewBatch returns a new batch +func (db *DatabaseClient) NewBatch() database.Batch { return &batch{db: db} } + +// NewIterator implements the Database interface +func (db *DatabaseClient) NewIterator() database.Iterator { + return db.NewIteratorWithStartAndPrefix(nil, nil) +} + +// NewIteratorWithStart implements the Database interface +func (db *DatabaseClient) NewIteratorWithStart(start []byte) database.Iterator { + return db.NewIteratorWithStartAndPrefix(start, nil) +} + +// NewIteratorWithPrefix implements the Database interface +func (db *DatabaseClient) NewIteratorWithPrefix(prefix []byte) database.Iterator { + return db.NewIteratorWithStartAndPrefix(nil, prefix) +} + +// NewIteratorWithStartAndPrefix returns a new empty iterator +func (db *DatabaseClient) NewIteratorWithStartAndPrefix(start, prefix []byte) database.Iterator { + resp, err := db.client.NewIteratorWithStartAndPrefix(context.Background(), &proto.NewIteratorWithStartAndPrefixRequest{ + Start: start, + Prefix: prefix, + }) + if err != nil { + return &nodb.Iterator{Err: updateError(err)} + } + return &iterator{ + db: db, + id: resp.Id, + } +} + +// Stat returns an error +func (db *DatabaseClient) Stat(property string) (string, error) { + resp, err := db.client.Stat(context.Background(), &proto.StatRequest{ + Property: property, + }) + if err != nil { + return "", updateError(err) + } + return resp.Stat, nil +} + +// Compact returns nil +func (db *DatabaseClient) Compact(start, limit []byte) error { + _, err := db.client.Compact(context.Background(), &proto.CompactRequest{ + Start: start, + Limit: limit, + }) + return updateError(err) +} + +// Close returns nil +func (db *DatabaseClient) Close() error { + _, err := db.client.Close(context.Background(), &proto.CloseRequest{}) + return updateError(err) +} + +type keyValue struct { + key []byte + value []byte + delete bool +} + +type batch struct { + db *DatabaseClient + writes []keyValue + size int +} + +func (b *batch) Put(key, value []byte) error { + b.writes = append(b.writes, keyValue{copyBytes(key), copyBytes(value), false}) + b.size += len(value) + return nil +} + +func (b *batch) Delete(key []byte) error { + b.writes = append(b.writes, keyValue{copyBytes(key), nil, true}) + b.size++ + return nil +} + +func (b *batch) ValueSize() int { return b.size } + +func (b *batch) Write() error { + request := &proto.WriteBatchRequest{} + + keySet := make(map[string]struct{}, len(b.writes)) + for i := len(b.writes) - 1; i >= 0; i-- { + kv := b.writes[i] + key := string(kv.key) + if _, overwritten := keySet[key]; overwritten { + continue + } + keySet[key] = struct{}{} + + if kv.delete { + request.Deletes = append(request.Deletes, &proto.DeleteRequest{ + Key: kv.key, + }) + } else { + request.Puts = append(request.Puts, &proto.PutRequest{ + Key: kv.key, + Value: kv.value, + }) + } + } + + _, err := b.db.client.WriteBatch(context.Background(), request) + return updateError(err) +} + +func (b *batch) Reset() { + b.writes = b.writes[:0] + b.size = 0 +} + +func (b *batch) Replay(w database.KeyValueWriter) error { + for _, keyvalue := range b.writes { + if keyvalue.delete { + if err := w.Delete(keyvalue.key); err != nil { + return err + } + } else if err := w.Put(keyvalue.key, keyvalue.value); err != nil { + return err + } + } + return nil +} + +func (b *batch) Inner() database.Batch { return b } + +type iterator struct { + db *DatabaseClient + id uint64 + key []byte + value []byte + err error +} + +// Next returns false +func (it *iterator) Next() bool { + resp, err := it.db.client.IteratorNext(context.Background(), &proto.IteratorNextRequest{ + Id: it.id, + }) + if err != nil { + it.err = err + return false + } + it.key = resp.Key + it.value = resp.Value + return resp.FoundNext +} + +// Error returns any errors +func (it *iterator) Error() error { + if it.err != nil { + return it.err + } + + _, err := it.db.client.IteratorError(context.Background(), &proto.IteratorErrorRequest{ + Id: it.id, + }) + it.err = updateError(err) + return it.err +} + +// Key returns nil +func (it *iterator) Key() []byte { return it.key } + +// Value returns nil +func (it *iterator) Value() []byte { return it.value } + +// Release does nothing +func (it *iterator) Release() { + it.db.client.IteratorRelease(context.Background(), &proto.IteratorReleaseRequest{ + Id: it.id, + }) +} + +func copyBytes(bytes []byte) []byte { + copiedBytes := make([]byte, len(bytes)) + copy(copiedBytes, bytes) + return copiedBytes +} + +func updateError(err error) error { + if err == nil { + return nil + } + + switch err.Error() { + case errClosed: + return database.ErrClosed + case errNotFound: + return database.ErrNotFound + default: + return err + } +} diff --git a/database/rpcdb/db_server.go b/database/rpcdb/db_server.go new file mode 100644 index 0000000..5abc3be --- /dev/null +++ b/database/rpcdb/db_server.go @@ -0,0 +1,143 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package rpcdb + +import ( + "errors" + + "golang.org/x/net/context" + + "github.com/ava-labs/gecko/database" + "github.com/ava-labs/gecko/database/rpcdb/proto" +) + +var ( + errUnknownIterator = errors.New("unknown iterator") +) + +// DatabaseServer is a database that is managed over RPC. +type DatabaseServer struct { + db database.Database + batch database.Batch + + nextIteratorID uint64 + iterators map[uint64]database.Iterator +} + +// NewServer returns a database instance that is managed remotely +func NewServer(db database.Database) *DatabaseServer { + return &DatabaseServer{ + db: db, + batch: db.NewBatch(), + iterators: make(map[uint64]database.Iterator), + } +} + +// Has ... +func (db *DatabaseServer) Has(_ context.Context, req *proto.HasRequest) (*proto.HasResponse, error) { + has, err := db.db.Has(req.Key) + if err != nil { + return nil, err + } + return &proto.HasResponse{Has: has}, nil +} + +// Get ... +func (db *DatabaseServer) Get(_ context.Context, req *proto.GetRequest) (*proto.GetResponse, error) { + value, err := db.db.Get(req.Key) + if err != nil { + return nil, err + } + return &proto.GetResponse{Value: value}, nil +} + +// Put ... +func (db *DatabaseServer) Put(_ context.Context, req *proto.PutRequest) (*proto.PutResponse, error) { + return &proto.PutResponse{}, db.db.Put(req.Key, req.Value) +} + +// Delete ... +func (db *DatabaseServer) Delete(_ context.Context, req *proto.DeleteRequest) (*proto.DeleteResponse, error) { + return &proto.DeleteResponse{}, db.db.Delete(req.Key) +} + +// Stat ... +func (db *DatabaseServer) Stat(_ context.Context, req *proto.StatRequest) (*proto.StatResponse, error) { + stat, err := db.db.Stat(req.Property) + if err != nil { + return nil, err + } + return &proto.StatResponse{Stat: stat}, nil +} + +// Compact ... +func (db *DatabaseServer) Compact(_ context.Context, req *proto.CompactRequest) (*proto.CompactResponse, error) { + return &proto.CompactResponse{}, db.db.Compact(req.Start, req.Limit) +} + +// Close ... +func (db *DatabaseServer) Close(_ context.Context, _ *proto.CloseRequest) (*proto.CloseResponse, error) { + return &proto.CloseResponse{}, db.db.Close() +} + +// WriteBatch ... +func (db *DatabaseServer) WriteBatch(_ context.Context, req *proto.WriteBatchRequest) (*proto.WriteBatchResponse, error) { + db.batch.Reset() + + for _, put := range req.Puts { + if err := db.batch.Put(put.Key, put.Value); err != nil { + return nil, err + } + } + + for _, del := range req.Deletes { + if err := db.batch.Delete(del.Key); err != nil { + return nil, err + } + } + + return &proto.WriteBatchResponse{}, db.batch.Write() +} + +// NewIteratorWithStartAndPrefix ... +func (db *DatabaseServer) NewIteratorWithStartAndPrefix(_ context.Context, req *proto.NewIteratorWithStartAndPrefixRequest) (*proto.NewIteratorWithStartAndPrefixResponse, error) { + id := db.nextIteratorID + it := db.db.NewIteratorWithStartAndPrefix(req.Start, req.Prefix) + db.iterators[id] = it + + db.nextIteratorID++ + return &proto.NewIteratorWithStartAndPrefixResponse{Id: id}, nil +} + +// IteratorNext ... +func (db *DatabaseServer) IteratorNext(_ context.Context, req *proto.IteratorNextRequest) (*proto.IteratorNextResponse, error) { + it, exists := db.iterators[req.Id] + if !exists { + return nil, errUnknownIterator + } + return &proto.IteratorNextResponse{ + FoundNext: it.Next(), + Key: it.Key(), + Value: it.Value(), + }, nil +} + +// IteratorError ... +func (db *DatabaseServer) IteratorError(_ context.Context, req *proto.IteratorErrorRequest) (*proto.IteratorErrorResponse, error) { + it, exists := db.iterators[req.Id] + if !exists { + return nil, errUnknownIterator + } + return &proto.IteratorErrorResponse{}, it.Error() +} + +// IteratorRelease ... +func (db *DatabaseServer) IteratorRelease(_ context.Context, req *proto.IteratorReleaseRequest) (*proto.IteratorReleaseResponse, error) { + it, exists := db.iterators[req.Id] + if exists { + delete(db.iterators, req.Id) + it.Release() + } + return &proto.IteratorReleaseResponse{}, nil +} diff --git a/database/rpcdb/db_test.go b/database/rpcdb/db_test.go new file mode 100644 index 0000000..ae833d5 --- /dev/null +++ b/database/rpcdb/db_test.go @@ -0,0 +1,51 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package rpcdb + +import ( + "log" + "net" + "testing" + + "golang.org/x/net/context" + + "google.golang.org/grpc" + "google.golang.org/grpc/test/bufconn" + + "github.com/ava-labs/gecko/database" + "github.com/ava-labs/gecko/database/memdb" + "github.com/ava-labs/gecko/database/rpcdb/proto" +) + +const ( + bufSize = 1 << 20 +) + +func TestInterface(t *testing.T) { + for _, test := range database.Tests { + listener := bufconn.Listen(bufSize) + server := grpc.NewServer() + proto.RegisterDatabaseServer(server, NewServer(memdb.New())) + go func() { + if err := server.Serve(listener); err != nil { + log.Fatalf("Server exited with error: %v", err) + } + }() + + dialer := grpc.WithContextDialer( + func(context.Context, string) (net.Conn, error) { + return listener.Dial() + }) + + ctx := context.Background() + conn, err := grpc.DialContext(ctx, "", dialer, grpc.WithInsecure()) + if err != nil { + t.Fatalf("Failed to dial: %s", err) + } + + db := NewClient(proto.NewDatabaseClient(conn)) + test(t, db) + conn.Close() + } +} diff --git a/database/rpcdb/proto/db.pb.go b/database/rpcdb/proto/db.pb.go new file mode 100644 index 0000000..452bad7 --- /dev/null +++ b/database/rpcdb/proto/db.pb.go @@ -0,0 +1,1526 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: db.proto + +package proto + +import ( + context "context" + fmt "fmt" + proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type HasRequest struct { + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *HasRequest) Reset() { *m = HasRequest{} } +func (m *HasRequest) String() string { return proto.CompactTextString(m) } +func (*HasRequest) ProtoMessage() {} +func (*HasRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{0} +} + +func (m *HasRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_HasRequest.Unmarshal(m, b) +} +func (m *HasRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_HasRequest.Marshal(b, m, deterministic) +} +func (m *HasRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_HasRequest.Merge(m, src) +} +func (m *HasRequest) XXX_Size() int { + return xxx_messageInfo_HasRequest.Size(m) +} +func (m *HasRequest) XXX_DiscardUnknown() { + xxx_messageInfo_HasRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_HasRequest proto.InternalMessageInfo + +func (m *HasRequest) GetKey() []byte { + if m != nil { + return m.Key + } + return nil +} + +type HasResponse struct { + Has bool `protobuf:"varint,1,opt,name=has,proto3" json:"has,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *HasResponse) Reset() { *m = HasResponse{} } +func (m *HasResponse) String() string { return proto.CompactTextString(m) } +func (*HasResponse) ProtoMessage() {} +func (*HasResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{1} +} + +func (m *HasResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_HasResponse.Unmarshal(m, b) +} +func (m *HasResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_HasResponse.Marshal(b, m, deterministic) +} +func (m *HasResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_HasResponse.Merge(m, src) +} +func (m *HasResponse) XXX_Size() int { + return xxx_messageInfo_HasResponse.Size(m) +} +func (m *HasResponse) XXX_DiscardUnknown() { + xxx_messageInfo_HasResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_HasResponse proto.InternalMessageInfo + +func (m *HasResponse) GetHas() bool { + if m != nil { + return m.Has + } + return false +} + +type GetRequest struct { + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetRequest) Reset() { *m = GetRequest{} } +func (m *GetRequest) String() string { return proto.CompactTextString(m) } +func (*GetRequest) ProtoMessage() {} +func (*GetRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{2} +} + +func (m *GetRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetRequest.Unmarshal(m, b) +} +func (m *GetRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetRequest.Marshal(b, m, deterministic) +} +func (m *GetRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetRequest.Merge(m, src) +} +func (m *GetRequest) XXX_Size() int { + return xxx_messageInfo_GetRequest.Size(m) +} +func (m *GetRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GetRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GetRequest proto.InternalMessageInfo + +func (m *GetRequest) GetKey() []byte { + if m != nil { + return m.Key + } + return nil +} + +type GetResponse struct { + Value []byte `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetResponse) Reset() { *m = GetResponse{} } +func (m *GetResponse) String() string { return proto.CompactTextString(m) } +func (*GetResponse) ProtoMessage() {} +func (*GetResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{3} +} + +func (m *GetResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetResponse.Unmarshal(m, b) +} +func (m *GetResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetResponse.Marshal(b, m, deterministic) +} +func (m *GetResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetResponse.Merge(m, src) +} +func (m *GetResponse) XXX_Size() int { + return xxx_messageInfo_GetResponse.Size(m) +} +func (m *GetResponse) XXX_DiscardUnknown() { + xxx_messageInfo_GetResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_GetResponse proto.InternalMessageInfo + +func (m *GetResponse) GetValue() []byte { + if m != nil { + return m.Value + } + return nil +} + +type PutRequest struct { + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *PutRequest) Reset() { *m = PutRequest{} } +func (m *PutRequest) String() string { return proto.CompactTextString(m) } +func (*PutRequest) ProtoMessage() {} +func (*PutRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{4} +} + +func (m *PutRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_PutRequest.Unmarshal(m, b) +} +func (m *PutRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_PutRequest.Marshal(b, m, deterministic) +} +func (m *PutRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_PutRequest.Merge(m, src) +} +func (m *PutRequest) XXX_Size() int { + return xxx_messageInfo_PutRequest.Size(m) +} +func (m *PutRequest) XXX_DiscardUnknown() { + xxx_messageInfo_PutRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_PutRequest proto.InternalMessageInfo + +func (m *PutRequest) GetKey() []byte { + if m != nil { + return m.Key + } + return nil +} + +func (m *PutRequest) GetValue() []byte { + if m != nil { + return m.Value + } + return nil +} + +type PutResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *PutResponse) Reset() { *m = PutResponse{} } +func (m *PutResponse) String() string { return proto.CompactTextString(m) } +func (*PutResponse) ProtoMessage() {} +func (*PutResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{5} +} + +func (m *PutResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_PutResponse.Unmarshal(m, b) +} +func (m *PutResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_PutResponse.Marshal(b, m, deterministic) +} +func (m *PutResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_PutResponse.Merge(m, src) +} +func (m *PutResponse) XXX_Size() int { + return xxx_messageInfo_PutResponse.Size(m) +} +func (m *PutResponse) XXX_DiscardUnknown() { + xxx_messageInfo_PutResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_PutResponse proto.InternalMessageInfo + +type DeleteRequest struct { + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } +func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } +func (*DeleteRequest) ProtoMessage() {} +func (*DeleteRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{6} +} + +func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeleteRequest.Unmarshal(m, b) +} +func (m *DeleteRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeleteRequest.Marshal(b, m, deterministic) +} +func (m *DeleteRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteRequest.Merge(m, src) +} +func (m *DeleteRequest) XXX_Size() int { + return xxx_messageInfo_DeleteRequest.Size(m) +} +func (m *DeleteRequest) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleteRequest proto.InternalMessageInfo + +func (m *DeleteRequest) GetKey() []byte { + if m != nil { + return m.Key + } + return nil +} + +type DeleteResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } +func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } +func (*DeleteResponse) ProtoMessage() {} +func (*DeleteResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{7} +} + +func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeleteResponse.Unmarshal(m, b) +} +func (m *DeleteResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeleteResponse.Marshal(b, m, deterministic) +} +func (m *DeleteResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteResponse.Merge(m, src) +} +func (m *DeleteResponse) XXX_Size() int { + return xxx_messageInfo_DeleteResponse.Size(m) +} +func (m *DeleteResponse) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleteResponse proto.InternalMessageInfo + +type StatRequest struct { + Property string `protobuf:"bytes,1,opt,name=property,proto3" json:"property,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *StatRequest) Reset() { *m = StatRequest{} } +func (m *StatRequest) String() string { return proto.CompactTextString(m) } +func (*StatRequest) ProtoMessage() {} +func (*StatRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{8} +} + +func (m *StatRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_StatRequest.Unmarshal(m, b) +} +func (m *StatRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_StatRequest.Marshal(b, m, deterministic) +} +func (m *StatRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_StatRequest.Merge(m, src) +} +func (m *StatRequest) XXX_Size() int { + return xxx_messageInfo_StatRequest.Size(m) +} +func (m *StatRequest) XXX_DiscardUnknown() { + xxx_messageInfo_StatRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_StatRequest proto.InternalMessageInfo + +func (m *StatRequest) GetProperty() string { + if m != nil { + return m.Property + } + return "" +} + +type StatResponse struct { + Stat string `protobuf:"bytes,1,opt,name=stat,proto3" json:"stat,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *StatResponse) Reset() { *m = StatResponse{} } +func (m *StatResponse) String() string { return proto.CompactTextString(m) } +func (*StatResponse) ProtoMessage() {} +func (*StatResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{9} +} + +func (m *StatResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_StatResponse.Unmarshal(m, b) +} +func (m *StatResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_StatResponse.Marshal(b, m, deterministic) +} +func (m *StatResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_StatResponse.Merge(m, src) +} +func (m *StatResponse) XXX_Size() int { + return xxx_messageInfo_StatResponse.Size(m) +} +func (m *StatResponse) XXX_DiscardUnknown() { + xxx_messageInfo_StatResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_StatResponse proto.InternalMessageInfo + +func (m *StatResponse) GetStat() string { + if m != nil { + return m.Stat + } + return "" +} + +type CompactRequest struct { + Start []byte `protobuf:"bytes,1,opt,name=start,proto3" json:"start,omitempty"` + Limit []byte `protobuf:"bytes,2,opt,name=limit,proto3" json:"limit,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CompactRequest) Reset() { *m = CompactRequest{} } +func (m *CompactRequest) String() string { return proto.CompactTextString(m) } +func (*CompactRequest) ProtoMessage() {} +func (*CompactRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{10} +} + +func (m *CompactRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CompactRequest.Unmarshal(m, b) +} +func (m *CompactRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CompactRequest.Marshal(b, m, deterministic) +} +func (m *CompactRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_CompactRequest.Merge(m, src) +} +func (m *CompactRequest) XXX_Size() int { + return xxx_messageInfo_CompactRequest.Size(m) +} +func (m *CompactRequest) XXX_DiscardUnknown() { + xxx_messageInfo_CompactRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_CompactRequest proto.InternalMessageInfo + +func (m *CompactRequest) GetStart() []byte { + if m != nil { + return m.Start + } + return nil +} + +func (m *CompactRequest) GetLimit() []byte { + if m != nil { + return m.Limit + } + return nil +} + +type CompactResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CompactResponse) Reset() { *m = CompactResponse{} } +func (m *CompactResponse) String() string { return proto.CompactTextString(m) } +func (*CompactResponse) ProtoMessage() {} +func (*CompactResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{11} +} + +func (m *CompactResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CompactResponse.Unmarshal(m, b) +} +func (m *CompactResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CompactResponse.Marshal(b, m, deterministic) +} +func (m *CompactResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_CompactResponse.Merge(m, src) +} +func (m *CompactResponse) XXX_Size() int { + return xxx_messageInfo_CompactResponse.Size(m) +} +func (m *CompactResponse) XXX_DiscardUnknown() { + xxx_messageInfo_CompactResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_CompactResponse proto.InternalMessageInfo + +type CloseRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CloseRequest) Reset() { *m = CloseRequest{} } +func (m *CloseRequest) String() string { return proto.CompactTextString(m) } +func (*CloseRequest) ProtoMessage() {} +func (*CloseRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{12} +} + +func (m *CloseRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CloseRequest.Unmarshal(m, b) +} +func (m *CloseRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CloseRequest.Marshal(b, m, deterministic) +} +func (m *CloseRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_CloseRequest.Merge(m, src) +} +func (m *CloseRequest) XXX_Size() int { + return xxx_messageInfo_CloseRequest.Size(m) +} +func (m *CloseRequest) XXX_DiscardUnknown() { + xxx_messageInfo_CloseRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_CloseRequest proto.InternalMessageInfo + +type CloseResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CloseResponse) Reset() { *m = CloseResponse{} } +func (m *CloseResponse) String() string { return proto.CompactTextString(m) } +func (*CloseResponse) ProtoMessage() {} +func (*CloseResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{13} +} + +func (m *CloseResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CloseResponse.Unmarshal(m, b) +} +func (m *CloseResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CloseResponse.Marshal(b, m, deterministic) +} +func (m *CloseResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_CloseResponse.Merge(m, src) +} +func (m *CloseResponse) XXX_Size() int { + return xxx_messageInfo_CloseResponse.Size(m) +} +func (m *CloseResponse) XXX_DiscardUnknown() { + xxx_messageInfo_CloseResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_CloseResponse proto.InternalMessageInfo + +type WriteBatchRequest struct { + Puts []*PutRequest `protobuf:"bytes,1,rep,name=puts,proto3" json:"puts,omitempty"` + Deletes []*DeleteRequest `protobuf:"bytes,2,rep,name=deletes,proto3" json:"deletes,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *WriteBatchRequest) Reset() { *m = WriteBatchRequest{} } +func (m *WriteBatchRequest) String() string { return proto.CompactTextString(m) } +func (*WriteBatchRequest) ProtoMessage() {} +func (*WriteBatchRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{14} +} + +func (m *WriteBatchRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_WriteBatchRequest.Unmarshal(m, b) +} +func (m *WriteBatchRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_WriteBatchRequest.Marshal(b, m, deterministic) +} +func (m *WriteBatchRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_WriteBatchRequest.Merge(m, src) +} +func (m *WriteBatchRequest) XXX_Size() int { + return xxx_messageInfo_WriteBatchRequest.Size(m) +} +func (m *WriteBatchRequest) XXX_DiscardUnknown() { + xxx_messageInfo_WriteBatchRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_WriteBatchRequest proto.InternalMessageInfo + +func (m *WriteBatchRequest) GetPuts() []*PutRequest { + if m != nil { + return m.Puts + } + return nil +} + +func (m *WriteBatchRequest) GetDeletes() []*DeleteRequest { + if m != nil { + return m.Deletes + } + return nil +} + +type WriteBatchResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *WriteBatchResponse) Reset() { *m = WriteBatchResponse{} } +func (m *WriteBatchResponse) String() string { return proto.CompactTextString(m) } +func (*WriteBatchResponse) ProtoMessage() {} +func (*WriteBatchResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{15} +} + +func (m *WriteBatchResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_WriteBatchResponse.Unmarshal(m, b) +} +func (m *WriteBatchResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_WriteBatchResponse.Marshal(b, m, deterministic) +} +func (m *WriteBatchResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_WriteBatchResponse.Merge(m, src) +} +func (m *WriteBatchResponse) XXX_Size() int { + return xxx_messageInfo_WriteBatchResponse.Size(m) +} +func (m *WriteBatchResponse) XXX_DiscardUnknown() { + xxx_messageInfo_WriteBatchResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_WriteBatchResponse proto.InternalMessageInfo + +type NewIteratorRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *NewIteratorRequest) Reset() { *m = NewIteratorRequest{} } +func (m *NewIteratorRequest) String() string { return proto.CompactTextString(m) } +func (*NewIteratorRequest) ProtoMessage() {} +func (*NewIteratorRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{16} +} + +func (m *NewIteratorRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_NewIteratorRequest.Unmarshal(m, b) +} +func (m *NewIteratorRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_NewIteratorRequest.Marshal(b, m, deterministic) +} +func (m *NewIteratorRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_NewIteratorRequest.Merge(m, src) +} +func (m *NewIteratorRequest) XXX_Size() int { + return xxx_messageInfo_NewIteratorRequest.Size(m) +} +func (m *NewIteratorRequest) XXX_DiscardUnknown() { + xxx_messageInfo_NewIteratorRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_NewIteratorRequest proto.InternalMessageInfo + +type NewIteratorWithStartAndPrefixRequest struct { + Start []byte `protobuf:"bytes,1,opt,name=start,proto3" json:"start,omitempty"` + Prefix []byte `protobuf:"bytes,2,opt,name=prefix,proto3" json:"prefix,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *NewIteratorWithStartAndPrefixRequest) Reset() { *m = NewIteratorWithStartAndPrefixRequest{} } +func (m *NewIteratorWithStartAndPrefixRequest) String() string { return proto.CompactTextString(m) } +func (*NewIteratorWithStartAndPrefixRequest) ProtoMessage() {} +func (*NewIteratorWithStartAndPrefixRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{17} +} + +func (m *NewIteratorWithStartAndPrefixRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_NewIteratorWithStartAndPrefixRequest.Unmarshal(m, b) +} +func (m *NewIteratorWithStartAndPrefixRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_NewIteratorWithStartAndPrefixRequest.Marshal(b, m, deterministic) +} +func (m *NewIteratorWithStartAndPrefixRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_NewIteratorWithStartAndPrefixRequest.Merge(m, src) +} +func (m *NewIteratorWithStartAndPrefixRequest) XXX_Size() int { + return xxx_messageInfo_NewIteratorWithStartAndPrefixRequest.Size(m) +} +func (m *NewIteratorWithStartAndPrefixRequest) XXX_DiscardUnknown() { + xxx_messageInfo_NewIteratorWithStartAndPrefixRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_NewIteratorWithStartAndPrefixRequest proto.InternalMessageInfo + +func (m *NewIteratorWithStartAndPrefixRequest) GetStart() []byte { + if m != nil { + return m.Start + } + return nil +} + +func (m *NewIteratorWithStartAndPrefixRequest) GetPrefix() []byte { + if m != nil { + return m.Prefix + } + return nil +} + +type NewIteratorWithStartAndPrefixResponse struct { + Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *NewIteratorWithStartAndPrefixResponse) Reset() { *m = NewIteratorWithStartAndPrefixResponse{} } +func (m *NewIteratorWithStartAndPrefixResponse) String() string { return proto.CompactTextString(m) } +func (*NewIteratorWithStartAndPrefixResponse) ProtoMessage() {} +func (*NewIteratorWithStartAndPrefixResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{18} +} + +func (m *NewIteratorWithStartAndPrefixResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_NewIteratorWithStartAndPrefixResponse.Unmarshal(m, b) +} +func (m *NewIteratorWithStartAndPrefixResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_NewIteratorWithStartAndPrefixResponse.Marshal(b, m, deterministic) +} +func (m *NewIteratorWithStartAndPrefixResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_NewIteratorWithStartAndPrefixResponse.Merge(m, src) +} +func (m *NewIteratorWithStartAndPrefixResponse) XXX_Size() int { + return xxx_messageInfo_NewIteratorWithStartAndPrefixResponse.Size(m) +} +func (m *NewIteratorWithStartAndPrefixResponse) XXX_DiscardUnknown() { + xxx_messageInfo_NewIteratorWithStartAndPrefixResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_NewIteratorWithStartAndPrefixResponse proto.InternalMessageInfo + +func (m *NewIteratorWithStartAndPrefixResponse) GetId() uint64 { + if m != nil { + return m.Id + } + return 0 +} + +type IteratorNextRequest struct { + Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *IteratorNextRequest) Reset() { *m = IteratorNextRequest{} } +func (m *IteratorNextRequest) String() string { return proto.CompactTextString(m) } +func (*IteratorNextRequest) ProtoMessage() {} +func (*IteratorNextRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{19} +} + +func (m *IteratorNextRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_IteratorNextRequest.Unmarshal(m, b) +} +func (m *IteratorNextRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_IteratorNextRequest.Marshal(b, m, deterministic) +} +func (m *IteratorNextRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_IteratorNextRequest.Merge(m, src) +} +func (m *IteratorNextRequest) XXX_Size() int { + return xxx_messageInfo_IteratorNextRequest.Size(m) +} +func (m *IteratorNextRequest) XXX_DiscardUnknown() { + xxx_messageInfo_IteratorNextRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_IteratorNextRequest proto.InternalMessageInfo + +func (m *IteratorNextRequest) GetId() uint64 { + if m != nil { + return m.Id + } + return 0 +} + +type IteratorNextResponse struct { + FoundNext bool `protobuf:"varint,1,opt,name=foundNext,proto3" json:"foundNext,omitempty"` + Key []byte `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` + Value []byte `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *IteratorNextResponse) Reset() { *m = IteratorNextResponse{} } +func (m *IteratorNextResponse) String() string { return proto.CompactTextString(m) } +func (*IteratorNextResponse) ProtoMessage() {} +func (*IteratorNextResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{20} +} + +func (m *IteratorNextResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_IteratorNextResponse.Unmarshal(m, b) +} +func (m *IteratorNextResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_IteratorNextResponse.Marshal(b, m, deterministic) +} +func (m *IteratorNextResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_IteratorNextResponse.Merge(m, src) +} +func (m *IteratorNextResponse) XXX_Size() int { + return xxx_messageInfo_IteratorNextResponse.Size(m) +} +func (m *IteratorNextResponse) XXX_DiscardUnknown() { + xxx_messageInfo_IteratorNextResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_IteratorNextResponse proto.InternalMessageInfo + +func (m *IteratorNextResponse) GetFoundNext() bool { + if m != nil { + return m.FoundNext + } + return false +} + +func (m *IteratorNextResponse) GetKey() []byte { + if m != nil { + return m.Key + } + return nil +} + +func (m *IteratorNextResponse) GetValue() []byte { + if m != nil { + return m.Value + } + return nil +} + +type IteratorErrorRequest struct { + Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *IteratorErrorRequest) Reset() { *m = IteratorErrorRequest{} } +func (m *IteratorErrorRequest) String() string { return proto.CompactTextString(m) } +func (*IteratorErrorRequest) ProtoMessage() {} +func (*IteratorErrorRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{21} +} + +func (m *IteratorErrorRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_IteratorErrorRequest.Unmarshal(m, b) +} +func (m *IteratorErrorRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_IteratorErrorRequest.Marshal(b, m, deterministic) +} +func (m *IteratorErrorRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_IteratorErrorRequest.Merge(m, src) +} +func (m *IteratorErrorRequest) XXX_Size() int { + return xxx_messageInfo_IteratorErrorRequest.Size(m) +} +func (m *IteratorErrorRequest) XXX_DiscardUnknown() { + xxx_messageInfo_IteratorErrorRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_IteratorErrorRequest proto.InternalMessageInfo + +func (m *IteratorErrorRequest) GetId() uint64 { + if m != nil { + return m.Id + } + return 0 +} + +type IteratorErrorResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *IteratorErrorResponse) Reset() { *m = IteratorErrorResponse{} } +func (m *IteratorErrorResponse) String() string { return proto.CompactTextString(m) } +func (*IteratorErrorResponse) ProtoMessage() {} +func (*IteratorErrorResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{22} +} + +func (m *IteratorErrorResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_IteratorErrorResponse.Unmarshal(m, b) +} +func (m *IteratorErrorResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_IteratorErrorResponse.Marshal(b, m, deterministic) +} +func (m *IteratorErrorResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_IteratorErrorResponse.Merge(m, src) +} +func (m *IteratorErrorResponse) XXX_Size() int { + return xxx_messageInfo_IteratorErrorResponse.Size(m) +} +func (m *IteratorErrorResponse) XXX_DiscardUnknown() { + xxx_messageInfo_IteratorErrorResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_IteratorErrorResponse proto.InternalMessageInfo + +type IteratorReleaseRequest struct { + Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *IteratorReleaseRequest) Reset() { *m = IteratorReleaseRequest{} } +func (m *IteratorReleaseRequest) String() string { return proto.CompactTextString(m) } +func (*IteratorReleaseRequest) ProtoMessage() {} +func (*IteratorReleaseRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{23} +} + +func (m *IteratorReleaseRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_IteratorReleaseRequest.Unmarshal(m, b) +} +func (m *IteratorReleaseRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_IteratorReleaseRequest.Marshal(b, m, deterministic) +} +func (m *IteratorReleaseRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_IteratorReleaseRequest.Merge(m, src) +} +func (m *IteratorReleaseRequest) XXX_Size() int { + return xxx_messageInfo_IteratorReleaseRequest.Size(m) +} +func (m *IteratorReleaseRequest) XXX_DiscardUnknown() { + xxx_messageInfo_IteratorReleaseRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_IteratorReleaseRequest proto.InternalMessageInfo + +func (m *IteratorReleaseRequest) GetId() uint64 { + if m != nil { + return m.Id + } + return 0 +} + +type IteratorReleaseResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *IteratorReleaseResponse) Reset() { *m = IteratorReleaseResponse{} } +func (m *IteratorReleaseResponse) String() string { return proto.CompactTextString(m) } +func (*IteratorReleaseResponse) ProtoMessage() {} +func (*IteratorReleaseResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_8817812184a13374, []int{24} +} + +func (m *IteratorReleaseResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_IteratorReleaseResponse.Unmarshal(m, b) +} +func (m *IteratorReleaseResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_IteratorReleaseResponse.Marshal(b, m, deterministic) +} +func (m *IteratorReleaseResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_IteratorReleaseResponse.Merge(m, src) +} +func (m *IteratorReleaseResponse) XXX_Size() int { + return xxx_messageInfo_IteratorReleaseResponse.Size(m) +} +func (m *IteratorReleaseResponse) XXX_DiscardUnknown() { + xxx_messageInfo_IteratorReleaseResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_IteratorReleaseResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*HasRequest)(nil), "proto.HasRequest") + proto.RegisterType((*HasResponse)(nil), "proto.HasResponse") + proto.RegisterType((*GetRequest)(nil), "proto.GetRequest") + proto.RegisterType((*GetResponse)(nil), "proto.GetResponse") + proto.RegisterType((*PutRequest)(nil), "proto.PutRequest") + proto.RegisterType((*PutResponse)(nil), "proto.PutResponse") + proto.RegisterType((*DeleteRequest)(nil), "proto.DeleteRequest") + proto.RegisterType((*DeleteResponse)(nil), "proto.DeleteResponse") + proto.RegisterType((*StatRequest)(nil), "proto.StatRequest") + proto.RegisterType((*StatResponse)(nil), "proto.StatResponse") + proto.RegisterType((*CompactRequest)(nil), "proto.CompactRequest") + proto.RegisterType((*CompactResponse)(nil), "proto.CompactResponse") + proto.RegisterType((*CloseRequest)(nil), "proto.CloseRequest") + proto.RegisterType((*CloseResponse)(nil), "proto.CloseResponse") + proto.RegisterType((*WriteBatchRequest)(nil), "proto.WriteBatchRequest") + proto.RegisterType((*WriteBatchResponse)(nil), "proto.WriteBatchResponse") + proto.RegisterType((*NewIteratorRequest)(nil), "proto.NewIteratorRequest") + proto.RegisterType((*NewIteratorWithStartAndPrefixRequest)(nil), "proto.NewIteratorWithStartAndPrefixRequest") + proto.RegisterType((*NewIteratorWithStartAndPrefixResponse)(nil), "proto.NewIteratorWithStartAndPrefixResponse") + proto.RegisterType((*IteratorNextRequest)(nil), "proto.IteratorNextRequest") + proto.RegisterType((*IteratorNextResponse)(nil), "proto.IteratorNextResponse") + proto.RegisterType((*IteratorErrorRequest)(nil), "proto.IteratorErrorRequest") + proto.RegisterType((*IteratorErrorResponse)(nil), "proto.IteratorErrorResponse") + proto.RegisterType((*IteratorReleaseRequest)(nil), "proto.IteratorReleaseRequest") + proto.RegisterType((*IteratorReleaseResponse)(nil), "proto.IteratorReleaseResponse") +} + +func init() { proto.RegisterFile("db.proto", fileDescriptor_8817812184a13374) } + +var fileDescriptor_8817812184a13374 = []byte{ + // 639 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0x5b, 0x4f, 0x13, 0x41, + 0x18, 0x0d, 0xbd, 0x51, 0x4e, 0x2f, 0xc0, 0xb0, 0xdc, 0x46, 0x40, 0x1d, 0xc5, 0x60, 0x6c, 0x30, + 0x41, 0x8d, 0x3e, 0xf8, 0x82, 0x60, 0x40, 0x1f, 0x48, 0xb3, 0x98, 0xf0, 0xe2, 0xcb, 0x40, 0x87, + 0xb0, 0x5a, 0xd8, 0x75, 0x77, 0xaa, 0xe8, 0xaf, 0xf0, 0x27, 0x9b, 0x9d, 0xfd, 0x66, 0x6f, 0x6d, + 0x91, 0xa7, 0xee, 0x7c, 0xdf, 0x39, 0x67, 0x66, 0xbe, 0x39, 0xa7, 0x68, 0x0e, 0xce, 0x77, 0x83, + 0xd0, 0xd7, 0x3e, 0xab, 0x9b, 0x1f, 0xb1, 0x05, 0x1c, 0xcb, 0xc8, 0x55, 0x3f, 0x46, 0x2a, 0xd2, + 0x6c, 0x01, 0xd5, 0xef, 0xea, 0xf7, 0xda, 0xcc, 0xa3, 0x99, 0x9d, 0xb6, 0x1b, 0x7f, 0x8a, 0x87, + 0x68, 0x99, 0x7e, 0x14, 0xf8, 0x37, 0x91, 0x8a, 0x01, 0x57, 0x32, 0x32, 0x80, 0xa6, 0x1b, 0x7f, + 0xc6, 0x02, 0x47, 0x4a, 0x4f, 0x17, 0x78, 0x82, 0x96, 0xe9, 0x93, 0x80, 0x83, 0xfa, 0x4f, 0x39, + 0x1c, 0x29, 0x82, 0x24, 0x0b, 0xf1, 0x1a, 0xe8, 0x8f, 0xa6, 0x8b, 0x64, 0xac, 0x4a, 0x9e, 0xd5, + 0x41, 0xcb, 0xb0, 0x12, 0x69, 0xf1, 0x18, 0x9d, 0x43, 0x35, 0x54, 0x5a, 0x4d, 0x3f, 0xcc, 0x02, + 0xba, 0x16, 0x42, 0xa4, 0xe7, 0x68, 0x9d, 0x6a, 0x99, 0x6e, 0xcd, 0xd1, 0x0c, 0x42, 0x3f, 0x50, + 0xa1, 0x4e, 0x78, 0x73, 0x6e, 0xba, 0x16, 0x02, 0xed, 0x04, 0x4a, 0x57, 0x61, 0xa8, 0x45, 0x5a, + 0x6a, 0xc2, 0x99, 0x6f, 0xf1, 0x1e, 0xdd, 0x03, 0xff, 0x3a, 0x90, 0x17, 0xa9, 0xa2, 0x83, 0x7a, + 0xa4, 0x65, 0xa8, 0xed, 0x85, 0xcd, 0x22, 0xae, 0x0e, 0xbd, 0x6b, 0x4f, 0xdb, 0x0b, 0x99, 0x85, + 0x58, 0xc4, 0x7c, 0xca, 0xa6, 0xf3, 0x75, 0xd1, 0x3e, 0x18, 0xfa, 0x91, 0xbd, 0x93, 0x98, 0x47, + 0x87, 0xd6, 0x04, 0xf8, 0x86, 0xc5, 0xb3, 0xd0, 0xd3, 0xea, 0x83, 0xd4, 0x17, 0x57, 0x76, 0xd3, + 0x6d, 0xd4, 0x82, 0x91, 0x8e, 0xdf, 0xa9, 0xba, 0xd3, 0xda, 0x5b, 0x4c, 0x9e, 0x7c, 0x37, 0x1b, + 0xb1, 0x6b, 0xda, 0x6c, 0x17, 0xb3, 0x03, 0x33, 0x8e, 0x68, 0xad, 0x62, 0x90, 0x0e, 0x21, 0x0b, + 0x73, 0x74, 0x2d, 0x48, 0x38, 0x60, 0xf9, 0xbd, 0xe8, 0x04, 0x0e, 0xd8, 0x89, 0xfa, 0xf5, 0x49, + 0xab, 0x50, 0x6a, 0x3f, 0xb4, 0x07, 0xfd, 0x82, 0xa7, 0xb9, 0xea, 0x99, 0xa7, 0xaf, 0x4e, 0xe3, + 0x9b, 0xef, 0xdf, 0x0c, 0xfa, 0xa1, 0xba, 0xf4, 0x6e, 0xef, 0x9e, 0xcf, 0x0a, 0x1a, 0x81, 0x81, + 0xd1, 0x80, 0x68, 0x25, 0xde, 0x62, 0xfb, 0x3f, 0xaa, 0xf4, 0x38, 0x5d, 0x54, 0xbc, 0x81, 0xd1, + 0xac, 0xb9, 0x15, 0x6f, 0x20, 0xb6, 0xb1, 0x64, 0x59, 0x27, 0xea, 0x36, 0x7d, 0x9d, 0x32, 0xec, + 0x2b, 0x9c, 0x22, 0x8c, 0xe4, 0x36, 0x30, 0x77, 0xe9, 0x8f, 0x6e, 0x06, 0x71, 0x91, 0xdc, 0x9f, + 0x15, 0xac, 0xd1, 0x2a, 0x13, 0x0c, 0x5b, 0xcd, 0x1b, 0xf6, 0x59, 0xa6, 0xfe, 0x31, 0x0c, 0xd3, + 0x59, 0x8d, 0x9d, 0x62, 0x15, 0xcb, 0x25, 0x1c, 0x8d, 0x7a, 0x07, 0x2b, 0xd9, 0x9c, 0x87, 0x4a, + 0xa6, 0xbe, 0x18, 0x93, 0x58, 0xc7, 0xea, 0x18, 0x32, 0x11, 0xd9, 0xfb, 0xdb, 0x40, 0xf3, 0x50, + 0x6a, 0x79, 0x2e, 0x23, 0xc5, 0x7a, 0xa8, 0x1e, 0xcb, 0x88, 0x59, 0x8b, 0x64, 0xff, 0x05, 0x9c, + 0xe5, 0x4b, 0x34, 0x86, 0x1e, 0xaa, 0x47, 0x4a, 0xa7, 0xe8, 0x2c, 0xf8, 0x29, 0x3a, 0x9f, 0xf5, + 0x1e, 0xaa, 0xfd, 0x51, 0x86, 0xce, 0xec, 0x97, 0xa2, 0x73, 0xf1, 0x65, 0x6f, 0xd0, 0x48, 0x6c, + 0xc7, 0x26, 0xba, 0x90, 0x2f, 0x97, 0xaa, 0x44, 0x7b, 0x89, 0x5a, 0x9c, 0x4a, 0x66, 0x25, 0x73, + 0x69, 0xe6, 0x4b, 0x85, 0x1a, 0x11, 0xde, 0x61, 0x96, 0x42, 0xc6, 0xac, 0x64, 0x31, 0xb2, 0x7c, + 0xa5, 0x5c, 0x26, 0xe6, 0x1e, 0xea, 0x26, 0x7b, 0xcc, 0xea, 0xe6, 0x93, 0xc9, 0x9d, 0x62, 0x91, + 0x38, 0xfb, 0x40, 0x16, 0x19, 0xb6, 0x46, 0x98, 0xb1, 0xc4, 0xf2, 0xf5, 0x09, 0x1d, 0x92, 0xf8, + 0x83, 0xcd, 0x3b, 0x3d, 0xcf, 0x5e, 0x10, 0xf7, 0x3e, 0x79, 0xe3, 0xbd, 0xfb, 0x81, 0x69, 0xef, + 0x23, 0xb4, 0xf3, 0x79, 0x60, 0x9c, 0xd8, 0x13, 0xb2, 0xc4, 0x1f, 0x4c, 0xec, 0x91, 0xd0, 0x67, + 0x74, 0x0a, 0x96, 0x66, 0x65, 0x74, 0x3e, 0x10, 0x7c, 0x63, 0x72, 0x93, 0xb4, 0xfa, 0x98, 0x2f, + 0x79, 0x9b, 0x6d, 0x96, 0x08, 0xc5, 0x74, 0xf0, 0xad, 0x69, 0xed, 0x44, 0xf1, 0xbc, 0x61, 0xda, + 0xaf, 0xfe, 0x05, 0x00, 0x00, 0xff, 0xff, 0x84, 0x99, 0x7f, 0xf3, 0x1f, 0x07, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConnInterface + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion6 + +// DatabaseClient is the client API for Database service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type DatabaseClient interface { + Has(ctx context.Context, in *HasRequest, opts ...grpc.CallOption) (*HasResponse, error) + Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) + Put(ctx context.Context, in *PutRequest, opts ...grpc.CallOption) (*PutResponse, error) + Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) + Stat(ctx context.Context, in *StatRequest, opts ...grpc.CallOption) (*StatResponse, error) + Compact(ctx context.Context, in *CompactRequest, opts ...grpc.CallOption) (*CompactResponse, error) + Close(ctx context.Context, in *CloseRequest, opts ...grpc.CallOption) (*CloseResponse, error) + WriteBatch(ctx context.Context, in *WriteBatchRequest, opts ...grpc.CallOption) (*WriteBatchResponse, error) + NewIteratorWithStartAndPrefix(ctx context.Context, in *NewIteratorWithStartAndPrefixRequest, opts ...grpc.CallOption) (*NewIteratorWithStartAndPrefixResponse, error) + IteratorNext(ctx context.Context, in *IteratorNextRequest, opts ...grpc.CallOption) (*IteratorNextResponse, error) + IteratorError(ctx context.Context, in *IteratorErrorRequest, opts ...grpc.CallOption) (*IteratorErrorResponse, error) + IteratorRelease(ctx context.Context, in *IteratorReleaseRequest, opts ...grpc.CallOption) (*IteratorReleaseResponse, error) +} + +type databaseClient struct { + cc grpc.ClientConnInterface +} + +func NewDatabaseClient(cc grpc.ClientConnInterface) DatabaseClient { + return &databaseClient{cc} +} + +func (c *databaseClient) Has(ctx context.Context, in *HasRequest, opts ...grpc.CallOption) (*HasResponse, error) { + out := new(HasResponse) + err := c.cc.Invoke(ctx, "/proto.Database/Has", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *databaseClient) Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) { + out := new(GetResponse) + err := c.cc.Invoke(ctx, "/proto.Database/Get", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *databaseClient) Put(ctx context.Context, in *PutRequest, opts ...grpc.CallOption) (*PutResponse, error) { + out := new(PutResponse) + err := c.cc.Invoke(ctx, "/proto.Database/Put", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *databaseClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { + out := new(DeleteResponse) + err := c.cc.Invoke(ctx, "/proto.Database/Delete", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *databaseClient) Stat(ctx context.Context, in *StatRequest, opts ...grpc.CallOption) (*StatResponse, error) { + out := new(StatResponse) + err := c.cc.Invoke(ctx, "/proto.Database/Stat", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *databaseClient) Compact(ctx context.Context, in *CompactRequest, opts ...grpc.CallOption) (*CompactResponse, error) { + out := new(CompactResponse) + err := c.cc.Invoke(ctx, "/proto.Database/Compact", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *databaseClient) Close(ctx context.Context, in *CloseRequest, opts ...grpc.CallOption) (*CloseResponse, error) { + out := new(CloseResponse) + err := c.cc.Invoke(ctx, "/proto.Database/Close", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *databaseClient) WriteBatch(ctx context.Context, in *WriteBatchRequest, opts ...grpc.CallOption) (*WriteBatchResponse, error) { + out := new(WriteBatchResponse) + err := c.cc.Invoke(ctx, "/proto.Database/WriteBatch", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *databaseClient) NewIteratorWithStartAndPrefix(ctx context.Context, in *NewIteratorWithStartAndPrefixRequest, opts ...grpc.CallOption) (*NewIteratorWithStartAndPrefixResponse, error) { + out := new(NewIteratorWithStartAndPrefixResponse) + err := c.cc.Invoke(ctx, "/proto.Database/NewIteratorWithStartAndPrefix", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *databaseClient) IteratorNext(ctx context.Context, in *IteratorNextRequest, opts ...grpc.CallOption) (*IteratorNextResponse, error) { + out := new(IteratorNextResponse) + err := c.cc.Invoke(ctx, "/proto.Database/IteratorNext", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *databaseClient) IteratorError(ctx context.Context, in *IteratorErrorRequest, opts ...grpc.CallOption) (*IteratorErrorResponse, error) { + out := new(IteratorErrorResponse) + err := c.cc.Invoke(ctx, "/proto.Database/IteratorError", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *databaseClient) IteratorRelease(ctx context.Context, in *IteratorReleaseRequest, opts ...grpc.CallOption) (*IteratorReleaseResponse, error) { + out := new(IteratorReleaseResponse) + err := c.cc.Invoke(ctx, "/proto.Database/IteratorRelease", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// DatabaseServer is the server API for Database service. +type DatabaseServer interface { + Has(context.Context, *HasRequest) (*HasResponse, error) + Get(context.Context, *GetRequest) (*GetResponse, error) + Put(context.Context, *PutRequest) (*PutResponse, error) + Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) + Stat(context.Context, *StatRequest) (*StatResponse, error) + Compact(context.Context, *CompactRequest) (*CompactResponse, error) + Close(context.Context, *CloseRequest) (*CloseResponse, error) + WriteBatch(context.Context, *WriteBatchRequest) (*WriteBatchResponse, error) + NewIteratorWithStartAndPrefix(context.Context, *NewIteratorWithStartAndPrefixRequest) (*NewIteratorWithStartAndPrefixResponse, error) + IteratorNext(context.Context, *IteratorNextRequest) (*IteratorNextResponse, error) + IteratorError(context.Context, *IteratorErrorRequest) (*IteratorErrorResponse, error) + IteratorRelease(context.Context, *IteratorReleaseRequest) (*IteratorReleaseResponse, error) +} + +// UnimplementedDatabaseServer can be embedded to have forward compatible implementations. +type UnimplementedDatabaseServer struct { +} + +func (*UnimplementedDatabaseServer) Has(ctx context.Context, req *HasRequest) (*HasResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Has not implemented") +} +func (*UnimplementedDatabaseServer) Get(ctx context.Context, req *GetRequest) (*GetResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Get not implemented") +} +func (*UnimplementedDatabaseServer) Put(ctx context.Context, req *PutRequest) (*PutResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Put not implemented") +} +func (*UnimplementedDatabaseServer) Delete(ctx context.Context, req *DeleteRequest) (*DeleteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") +} +func (*UnimplementedDatabaseServer) Stat(ctx context.Context, req *StatRequest) (*StatResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Stat not implemented") +} +func (*UnimplementedDatabaseServer) Compact(ctx context.Context, req *CompactRequest) (*CompactResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Compact not implemented") +} +func (*UnimplementedDatabaseServer) Close(ctx context.Context, req *CloseRequest) (*CloseResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Close not implemented") +} +func (*UnimplementedDatabaseServer) WriteBatch(ctx context.Context, req *WriteBatchRequest) (*WriteBatchResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method WriteBatch not implemented") +} +func (*UnimplementedDatabaseServer) NewIteratorWithStartAndPrefix(ctx context.Context, req *NewIteratorWithStartAndPrefixRequest) (*NewIteratorWithStartAndPrefixResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method NewIteratorWithStartAndPrefix not implemented") +} +func (*UnimplementedDatabaseServer) IteratorNext(ctx context.Context, req *IteratorNextRequest) (*IteratorNextResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method IteratorNext not implemented") +} +func (*UnimplementedDatabaseServer) IteratorError(ctx context.Context, req *IteratorErrorRequest) (*IteratorErrorResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method IteratorError not implemented") +} +func (*UnimplementedDatabaseServer) IteratorRelease(ctx context.Context, req *IteratorReleaseRequest) (*IteratorReleaseResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method IteratorRelease not implemented") +} + +func RegisterDatabaseServer(s *grpc.Server, srv DatabaseServer) { + s.RegisterService(&_Database_serviceDesc, srv) +} + +func _Database_Has_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(HasRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DatabaseServer).Has(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Database/Has", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DatabaseServer).Has(ctx, req.(*HasRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Database_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DatabaseServer).Get(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Database/Get", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DatabaseServer).Get(ctx, req.(*GetRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Database_Put_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(PutRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DatabaseServer).Put(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Database/Put", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DatabaseServer).Put(ctx, req.(*PutRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Database_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DatabaseServer).Delete(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Database/Delete", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DatabaseServer).Delete(ctx, req.(*DeleteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Database_Stat_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(StatRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DatabaseServer).Stat(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Database/Stat", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DatabaseServer).Stat(ctx, req.(*StatRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Database_Compact_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CompactRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DatabaseServer).Compact(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Database/Compact", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DatabaseServer).Compact(ctx, req.(*CompactRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Database_Close_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CloseRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DatabaseServer).Close(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Database/Close", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DatabaseServer).Close(ctx, req.(*CloseRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Database_WriteBatch_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(WriteBatchRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DatabaseServer).WriteBatch(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Database/WriteBatch", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DatabaseServer).WriteBatch(ctx, req.(*WriteBatchRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Database_NewIteratorWithStartAndPrefix_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(NewIteratorWithStartAndPrefixRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DatabaseServer).NewIteratorWithStartAndPrefix(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Database/NewIteratorWithStartAndPrefix", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DatabaseServer).NewIteratorWithStartAndPrefix(ctx, req.(*NewIteratorWithStartAndPrefixRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Database_IteratorNext_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(IteratorNextRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DatabaseServer).IteratorNext(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Database/IteratorNext", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DatabaseServer).IteratorNext(ctx, req.(*IteratorNextRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Database_IteratorError_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(IteratorErrorRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DatabaseServer).IteratorError(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Database/IteratorError", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DatabaseServer).IteratorError(ctx, req.(*IteratorErrorRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Database_IteratorRelease_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(IteratorReleaseRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DatabaseServer).IteratorRelease(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Database/IteratorRelease", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DatabaseServer).IteratorRelease(ctx, req.(*IteratorReleaseRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Database_serviceDesc = grpc.ServiceDesc{ + ServiceName: "proto.Database", + HandlerType: (*DatabaseServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Has", + Handler: _Database_Has_Handler, + }, + { + MethodName: "Get", + Handler: _Database_Get_Handler, + }, + { + MethodName: "Put", + Handler: _Database_Put_Handler, + }, + { + MethodName: "Delete", + Handler: _Database_Delete_Handler, + }, + { + MethodName: "Stat", + Handler: _Database_Stat_Handler, + }, + { + MethodName: "Compact", + Handler: _Database_Compact_Handler, + }, + { + MethodName: "Close", + Handler: _Database_Close_Handler, + }, + { + MethodName: "WriteBatch", + Handler: _Database_WriteBatch_Handler, + }, + { + MethodName: "NewIteratorWithStartAndPrefix", + Handler: _Database_NewIteratorWithStartAndPrefix_Handler, + }, + { + MethodName: "IteratorNext", + Handler: _Database_IteratorNext_Handler, + }, + { + MethodName: "IteratorError", + Handler: _Database_IteratorError_Handler, + }, + { + MethodName: "IteratorRelease", + Handler: _Database_IteratorRelease_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "db.proto", +} diff --git a/database/rpcdb/proto/db.proto b/database/rpcdb/proto/db.proto new file mode 100644 index 0000000..1f6f60c --- /dev/null +++ b/database/rpcdb/proto/db.proto @@ -0,0 +1,108 @@ +syntax = "proto3"; +package proto; + +message HasRequest { + bytes key = 1; +} + +message HasResponse { + bool has = 1; +} + +message GetRequest { + bytes key = 1; +} + +message GetResponse { + bytes value = 1; +} + +message PutRequest { + bytes key = 1; + bytes value = 2; +} + +message PutResponse {} + +message DeleteRequest { + bytes key = 1; +} + +message DeleteResponse {} + +message StatRequest { + string property = 1; +} + +message StatResponse { + string stat = 1; +} + +message CompactRequest { + bytes start = 1; + bytes limit = 2; +} + +message CompactResponse {} + +message CloseRequest {} + +message CloseResponse {} + +message WriteBatchRequest { + repeated PutRequest puts = 1; + repeated DeleteRequest deletes = 2; +} + +message WriteBatchResponse {} + +message NewIteratorRequest {} + +message NewIteratorWithStartAndPrefixRequest { + bytes start = 1; + bytes prefix = 2; +} + +message NewIteratorWithStartAndPrefixResponse { + uint64 id = 1; +} + +message IteratorNextRequest { + uint64 id = 1; +} + +message IteratorNextResponse { + bool foundNext = 1; + bytes key = 2; + bytes value = 3; +} + +message IteratorErrorRequest { + uint64 id = 1; +} + +message IteratorErrorResponse {} + +message IteratorReleaseRequest { + uint64 id = 1; +} + +message IteratorReleaseResponse {} + +service Database { + rpc Has(HasRequest) returns (HasResponse); + rpc Get(GetRequest) returns (GetResponse); + rpc Put(PutRequest) returns (PutResponse); + rpc Delete(DeleteRequest) returns (DeleteResponse); + rpc Stat(StatRequest) returns (StatResponse); + rpc Compact(CompactRequest) returns (CompactResponse); + rpc Close(CloseRequest) returns (CloseResponse); + + rpc WriteBatch(WriteBatchRequest) returns (WriteBatchResponse); + + rpc NewIteratorWithStartAndPrefix(NewIteratorWithStartAndPrefixRequest) returns (NewIteratorWithStartAndPrefixResponse); + + rpc IteratorNext(IteratorNextRequest) returns (IteratorNextResponse); + rpc IteratorError(IteratorErrorRequest) returns (IteratorErrorResponse); + rpc IteratorRelease(IteratorReleaseRequest) returns (IteratorReleaseResponse); +} \ No newline at end of file diff --git a/database/test_database.go b/database/test_database.go index d299bb1..2e33b25 100644 --- a/database/test_database.go +++ b/database/test_database.go @@ -16,6 +16,8 @@ var ( TestBatchPut, TestBatchDelete, TestBatchReset, + TestBatchReuse, + TestBatchRewrite, TestBatchReplay, TestBatchInner, TestIterator, @@ -236,6 +238,105 @@ func TestBatchReset(t *testing.T, db Database) { } } +// TestBatchReuse ... +func TestBatchReuse(t *testing.T, db Database) { + key1 := []byte("hello1") + value1 := []byte("world1") + + key2 := []byte("hello2") + value2 := []byte("world2") + + batch := db.NewBatch() + if batch == nil { + t.Fatalf("db.NewBatch returned nil") + } + + if err := batch.Put(key1, value1); err != nil { + t.Fatalf("Unexpected error on batch.Put: %s", err) + } + + if err := batch.Write(); err != nil { + t.Fatalf("Unexpected error on batch.Write: %s", err) + } + + if err := db.Delete(key1); err != nil { + t.Fatalf("Unexpected error on database.Delete: %s", err) + } + + if has, err := db.Has(key1); err != nil { + t.Fatalf("Unexpected error on db.Has: %s", err) + } else if has { + t.Fatalf("db.Has unexpectedly returned true on key %s", key1) + } + + batch.Reset() + + if err := batch.Put(key2, value2); err != nil { + t.Fatalf("Unexpected error on batch.Put: %s", err) + } + + if err := batch.Write(); err != nil { + t.Fatalf("Unexpected error on batch.Write: %s", err) + } + + if has, err := db.Has(key1); err != nil { + t.Fatalf("Unexpected error on db.Has: %s", err) + } else if has { + t.Fatalf("db.Has unexpectedly returned true on key %s", key1) + } else if has, err := db.Has(key2); err != nil { + t.Fatalf("Unexpected error on db.Has: %s", err) + } else if !has { + t.Fatalf("db.Has unexpectedly returned false on key %s", key2) + } else if v, err := db.Get(key2); err != nil { + t.Fatalf("Unexpected error on db.Get: %s", err) + } else if !bytes.Equal(value2, v) { + t.Fatalf("db.Get: Returned: 0x%x ; Expected: 0x%x", v, value2) + } +} + +// TestBatchRewrite ... +func TestBatchRewrite(t *testing.T, db Database) { + key := []byte("hello1") + value := []byte("world1") + + batch := db.NewBatch() + if batch == nil { + t.Fatalf("db.NewBatch returned nil") + } + + if err := batch.Put(key, value); err != nil { + t.Fatalf("Unexpected error on batch.Put: %s", err) + } + + if err := batch.Write(); err != nil { + t.Fatalf("Unexpected error on batch.Write: %s", err) + } + + if err := db.Delete(key); err != nil { + t.Fatalf("Unexpected error on database.Delete: %s", err) + } + + if has, err := db.Has(key); err != nil { + t.Fatalf("Unexpected error on db.Has: %s", err) + } else if has { + t.Fatalf("db.Has unexpectedly returned true on key %s", key) + } + + if err := batch.Write(); err != nil { + t.Fatalf("Unexpected error on batch.Write: %s", err) + } + + if has, err := db.Has(key); err != nil { + t.Fatalf("Unexpected error on db.Has: %s", err) + } else if !has { + t.Fatalf("db.Has unexpectedly returned false on key %s", key) + } else if v, err := db.Get(key); err != nil { + t.Fatalf("Unexpected error on db.Get: %s", err) + } else if !bytes.Equal(value, v) { + t.Fatalf("db.Get: Returned: 0x%x ; Expected: 0x%x", v, value) + } +} + // TestBatchReplay ... func TestBatchReplay(t *testing.T, db Database) { key1 := []byte("hello1") diff --git a/database/versiondb/versiondb.go b/database/versiondb/db.go similarity index 100% rename from database/versiondb/versiondb.go rename to database/versiondb/db.go diff --git a/database/versiondb/versiondb_test.go b/database/versiondb/db_test.go similarity index 100% rename from database/versiondb/versiondb_test.go rename to database/versiondb/db_test.go diff --git a/genesis/aliases.go b/genesis/aliases.go index 41ff25a..80e5dcd 100644 --- a/genesis/aliases.go +++ b/genesis/aliases.go @@ -6,7 +6,6 @@ package genesis import ( "github.com/ava-labs/gecko/ids" "github.com/ava-labs/gecko/vms/avm" - "github.com/ava-labs/gecko/vms/evm" "github.com/ava-labs/gecko/vms/nftfx" "github.com/ava-labs/gecko/vms/platformvm" "github.com/ava-labs/gecko/vms/propertyfx" @@ -21,7 +20,7 @@ func Aliases(networkID uint32) (map[string][]string, map[[32]byte][]string, map[ generalAliases := map[string][]string{ "vm/" + platformvm.ID.String(): []string{"vm/platform"}, "vm/" + avm.ID.String(): []string{"vm/avm"}, - "vm/" + evm.ID.String(): []string{"vm/evm"}, + "vm/" + EVMID.String(): []string{"vm/evm"}, "vm/" + spdagvm.ID.String(): []string{"vm/spdag"}, "vm/" + spchainvm.ID.String(): []string{"vm/spchain"}, "vm/" + timestampvm.ID.String(): []string{"vm/timestamp"}, @@ -33,7 +32,7 @@ func Aliases(networkID uint32) (map[string][]string, map[[32]byte][]string, map[ vmAliases := map[[32]byte][]string{ platformvm.ID.Key(): []string{"platform"}, avm.ID.Key(): []string{"avm"}, - evm.ID.Key(): []string{"evm"}, + EVMID.Key(): []string{"evm"}, spdagvm.ID.Key(): []string{"spdag"}, spchainvm.ID.Key(): []string{"spchain"}, timestampvm.ID.Key(): []string{"timestamp"}, @@ -60,7 +59,7 @@ func Aliases(networkID uint32) (map[string][]string, map[[32]byte][]string, map[ case avm.ID.Equals(chain.VMID): generalAliases["bc/"+chain.ID().String()] = []string{"X", "avm", "bc/X", "bc/avm"} chainAliases[chain.ID().Key()] = []string{"X", "avm"} - case evm.ID.Equals(chain.VMID): + case EVMID.Equals(chain.VMID): generalAliases["bc/"+chain.ID().String()] = []string{"C", "evm", "bc/C", "bc/evm"} chainAliases[chain.ID().Key()] = []string{"C", "evm"} case spdagvm.ID.Equals(chain.VMID): diff --git a/genesis/config.go b/genesis/config.go index 5db0302..ceab4d5 100644 --- a/genesis/config.go +++ b/genesis/config.go @@ -5,7 +5,6 @@ package genesis import ( "github.com/ava-labs/gecko/ids" - "github.com/ava-labs/gecko/vms/evm" ) // Note that since an AVA network has exactly one Platform Chain, @@ -16,8 +15,9 @@ import ( // Config contains the genesis addresses used to construct a genesis type Config struct { - MintAddresses, FundedAddresses, FundedEVMAddresses, StakerIDs []string - ParsedMintAddresses, ParsedFundedAddresses, ParsedStakerIDs []ids.ShortID + MintAddresses, FundedAddresses, StakerIDs []string + ParsedMintAddresses, ParsedFundedAddresses, ParsedStakerIDs []ids.ShortID + EVMBytes []byte } func (c *Config) init() error { @@ -66,9 +66,6 @@ var ( "ZdhZv6oZrmXLyFDy6ovXAu6VxmbTsT2h", "6cesTteH62Y5mLoDBUASaBvCXuL2AthL", }, - FundedEVMAddresses: []string{ - "0x572f4D80f10f663B5049F789546f25f70Bb62a7F", - }, StakerIDs: []string{ "NX4zVkuiRJZYe6Nzzav7GXN3TakUet3Co", "CMsa8cMw4eib1Hb8GG4xiUKAq5eE1BwUX", @@ -76,6 +73,98 @@ var ( "N86eodVZja3GEyZJTo3DFUPGpxEEvjGHs", "EkKeGSLUbHrrtuayBtbwgWDRUiAziC3ao", }, + EVMBytes: []byte{ + 0x7b, 0x22, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x22, 0x3a, 0x7b, 0x22, 0x63, 0x68, 0x61, 0x69, + 0x6e, 0x49, 0x64, 0x22, 0x3a, 0x34, 0x33, 0x31, + 0x31, 0x30, 0x2c, 0x22, 0x68, 0x6f, 0x6d, 0x65, + 0x73, 0x74, 0x65, 0x61, 0x64, 0x42, 0x6c, 0x6f, + 0x63, 0x6b, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x64, + 0x61, 0x6f, 0x46, 0x6f, 0x72, 0x6b, 0x42, 0x6c, + 0x6f, 0x63, 0x6b, 0x22, 0x3a, 0x30, 0x2c, 0x22, + 0x64, 0x61, 0x6f, 0x46, 0x6f, 0x72, 0x6b, 0x53, + 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x22, 0x3a, + 0x74, 0x72, 0x75, 0x65, 0x2c, 0x22, 0x65, 0x69, + 0x70, 0x31, 0x35, 0x30, 0x42, 0x6c, 0x6f, 0x63, + 0x6b, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x65, 0x69, + 0x70, 0x31, 0x35, 0x30, 0x48, 0x61, 0x73, 0x68, + 0x22, 0x3a, 0x22, 0x30, 0x78, 0x32, 0x30, 0x38, + 0x36, 0x37, 0x39, 0x39, 0x61, 0x65, 0x65, 0x62, + 0x65, 0x61, 0x65, 0x31, 0x33, 0x35, 0x63, 0x32, + 0x34, 0x36, 0x63, 0x36, 0x35, 0x30, 0x32, 0x31, + 0x63, 0x38, 0x32, 0x62, 0x34, 0x65, 0x31, 0x35, + 0x61, 0x32, 0x63, 0x34, 0x35, 0x31, 0x33, 0x34, + 0x30, 0x39, 0x39, 0x33, 0x61, 0x61, 0x63, 0x66, + 0x64, 0x32, 0x37, 0x35, 0x31, 0x38, 0x38, 0x36, + 0x35, 0x31, 0x34, 0x66, 0x30, 0x22, 0x2c, 0x22, + 0x65, 0x69, 0x70, 0x31, 0x35, 0x35, 0x42, 0x6c, + 0x6f, 0x63, 0x6b, 0x22, 0x3a, 0x30, 0x2c, 0x22, + 0x65, 0x69, 0x70, 0x31, 0x35, 0x38, 0x42, 0x6c, + 0x6f, 0x63, 0x6b, 0x22, 0x3a, 0x30, 0x2c, 0x22, + 0x62, 0x79, 0x7a, 0x61, 0x6e, 0x74, 0x69, 0x75, + 0x6d, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x3a, + 0x30, 0x2c, 0x22, 0x63, 0x6f, 0x6e, 0x73, 0x74, + 0x61, 0x6e, 0x74, 0x69, 0x6e, 0x6f, 0x70, 0x6c, + 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x3a, + 0x30, 0x2c, 0x22, 0x70, 0x65, 0x74, 0x65, 0x72, + 0x73, 0x62, 0x75, 0x72, 0x67, 0x42, 0x6c, 0x6f, + 0x63, 0x6b, 0x22, 0x3a, 0x30, 0x7d, 0x2c, 0x22, + 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x22, + 0x30, 0x78, 0x30, 0x22, 0x2c, 0x22, 0x74, 0x69, + 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, + 0x3a, 0x22, 0x30, 0x78, 0x30, 0x22, 0x2c, 0x22, + 0x65, 0x78, 0x74, 0x72, 0x61, 0x44, 0x61, 0x74, + 0x61, 0x22, 0x3a, 0x22, 0x30, 0x78, 0x30, 0x30, + 0x22, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x4c, 0x69, + 0x6d, 0x69, 0x74, 0x22, 0x3a, 0x22, 0x30, 0x78, + 0x35, 0x66, 0x35, 0x65, 0x31, 0x30, 0x30, 0x22, + 0x2c, 0x22, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63, + 0x75, 0x6c, 0x74, 0x79, 0x22, 0x3a, 0x22, 0x30, + 0x78, 0x30, 0x22, 0x2c, 0x22, 0x6d, 0x69, 0x78, + 0x48, 0x61, 0x73, 0x68, 0x22, 0x3a, 0x22, 0x30, + 0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x22, 0x2c, 0x22, 0x63, 0x6f, 0x69, 0x6e, + 0x62, 0x61, 0x73, 0x65, 0x22, 0x3a, 0x22, 0x30, + 0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x22, 0x2c, 0x22, 0x61, 0x6c, 0x6c, 0x6f, + 0x63, 0x22, 0x3a, 0x7b, 0x22, 0x35, 0x37, 0x32, + 0x66, 0x34, 0x64, 0x38, 0x30, 0x66, 0x31, 0x30, + 0x66, 0x36, 0x36, 0x33, 0x62, 0x35, 0x30, 0x34, + 0x39, 0x66, 0x37, 0x38, 0x39, 0x35, 0x34, 0x36, + 0x66, 0x32, 0x35, 0x66, 0x37, 0x30, 0x62, 0x62, + 0x36, 0x32, 0x61, 0x37, 0x66, 0x22, 0x3a, 0x7b, + 0x22, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, + 0x22, 0x3a, 0x22, 0x30, 0x78, 0x33, 0x33, 0x62, + 0x32, 0x65, 0x33, 0x63, 0x39, 0x66, 0x64, 0x30, + 0x38, 0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x22, 0x7d, 0x7d, 0x2c, + 0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, + 0x3a, 0x22, 0x30, 0x78, 0x30, 0x22, 0x2c, 0x22, + 0x67, 0x61, 0x73, 0x55, 0x73, 0x65, 0x64, 0x22, + 0x3a, 0x22, 0x30, 0x78, 0x30, 0x22, 0x2c, 0x22, + 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x48, 0x61, + 0x73, 0x68, 0x22, 0x3a, 0x22, 0x30, 0x78, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x22, + 0x7d, + }, } DefaultConfig = Config{ MintAddresses: []string{}, @@ -83,10 +172,6 @@ var ( // Private key: ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN "6Y3kysjF9jnHnYkdS9yGAuoHyae2eNmeV", }, - FundedEVMAddresses: []string{ - // Private key: evm.GenesisTestKey - evm.GenesisTestAddr, - }, StakerIDs: []string{ "7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg", "MFrZFVCXPv5iCn6M9K6XduxGTYp891xXZ", @@ -94,6 +179,98 @@ var ( "GWPcbFJZFfZreETSoWjPimr846mXEKCtu", "P7oB2McjBGgW2NXXWVYjV8JEDFoW9xDE5", }, + EVMBytes: []byte{ + 0x7b, 0x22, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x22, 0x3a, 0x7b, 0x22, 0x63, 0x68, 0x61, 0x69, + 0x6e, 0x49, 0x64, 0x22, 0x3a, 0x34, 0x33, 0x31, + 0x31, 0x30, 0x2c, 0x22, 0x68, 0x6f, 0x6d, 0x65, + 0x73, 0x74, 0x65, 0x61, 0x64, 0x42, 0x6c, 0x6f, + 0x63, 0x6b, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x64, + 0x61, 0x6f, 0x46, 0x6f, 0x72, 0x6b, 0x42, 0x6c, + 0x6f, 0x63, 0x6b, 0x22, 0x3a, 0x30, 0x2c, 0x22, + 0x64, 0x61, 0x6f, 0x46, 0x6f, 0x72, 0x6b, 0x53, + 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x22, 0x3a, + 0x74, 0x72, 0x75, 0x65, 0x2c, 0x22, 0x65, 0x69, + 0x70, 0x31, 0x35, 0x30, 0x42, 0x6c, 0x6f, 0x63, + 0x6b, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x65, 0x69, + 0x70, 0x31, 0x35, 0x30, 0x48, 0x61, 0x73, 0x68, + 0x22, 0x3a, 0x22, 0x30, 0x78, 0x32, 0x30, 0x38, + 0x36, 0x37, 0x39, 0x39, 0x61, 0x65, 0x65, 0x62, + 0x65, 0x61, 0x65, 0x31, 0x33, 0x35, 0x63, 0x32, + 0x34, 0x36, 0x63, 0x36, 0x35, 0x30, 0x32, 0x31, + 0x63, 0x38, 0x32, 0x62, 0x34, 0x65, 0x31, 0x35, + 0x61, 0x32, 0x63, 0x34, 0x35, 0x31, 0x33, 0x34, + 0x30, 0x39, 0x39, 0x33, 0x61, 0x61, 0x63, 0x66, + 0x64, 0x32, 0x37, 0x35, 0x31, 0x38, 0x38, 0x36, + 0x35, 0x31, 0x34, 0x66, 0x30, 0x22, 0x2c, 0x22, + 0x65, 0x69, 0x70, 0x31, 0x35, 0x35, 0x42, 0x6c, + 0x6f, 0x63, 0x6b, 0x22, 0x3a, 0x30, 0x2c, 0x22, + 0x65, 0x69, 0x70, 0x31, 0x35, 0x38, 0x42, 0x6c, + 0x6f, 0x63, 0x6b, 0x22, 0x3a, 0x30, 0x2c, 0x22, + 0x62, 0x79, 0x7a, 0x61, 0x6e, 0x74, 0x69, 0x75, + 0x6d, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x3a, + 0x30, 0x2c, 0x22, 0x63, 0x6f, 0x6e, 0x73, 0x74, + 0x61, 0x6e, 0x74, 0x69, 0x6e, 0x6f, 0x70, 0x6c, + 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x3a, + 0x30, 0x2c, 0x22, 0x70, 0x65, 0x74, 0x65, 0x72, + 0x73, 0x62, 0x75, 0x72, 0x67, 0x42, 0x6c, 0x6f, + 0x63, 0x6b, 0x22, 0x3a, 0x30, 0x7d, 0x2c, 0x22, + 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x22, + 0x30, 0x78, 0x30, 0x22, 0x2c, 0x22, 0x74, 0x69, + 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, + 0x3a, 0x22, 0x30, 0x78, 0x30, 0x22, 0x2c, 0x22, + 0x65, 0x78, 0x74, 0x72, 0x61, 0x44, 0x61, 0x74, + 0x61, 0x22, 0x3a, 0x22, 0x30, 0x78, 0x30, 0x30, + 0x22, 0x2c, 0x22, 0x67, 0x61, 0x73, 0x4c, 0x69, + 0x6d, 0x69, 0x74, 0x22, 0x3a, 0x22, 0x30, 0x78, + 0x35, 0x66, 0x35, 0x65, 0x31, 0x30, 0x30, 0x22, + 0x2c, 0x22, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63, + 0x75, 0x6c, 0x74, 0x79, 0x22, 0x3a, 0x22, 0x30, + 0x78, 0x30, 0x22, 0x2c, 0x22, 0x6d, 0x69, 0x78, + 0x48, 0x61, 0x73, 0x68, 0x22, 0x3a, 0x22, 0x30, + 0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x22, 0x2c, 0x22, 0x63, 0x6f, 0x69, 0x6e, + 0x62, 0x61, 0x73, 0x65, 0x22, 0x3a, 0x22, 0x30, + 0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x22, 0x2c, 0x22, 0x61, 0x6c, 0x6c, 0x6f, + 0x63, 0x22, 0x3a, 0x7b, 0x22, 0x37, 0x35, 0x31, + 0x61, 0x30, 0x62, 0x39, 0x36, 0x65, 0x31, 0x30, + 0x34, 0x32, 0x62, 0x65, 0x65, 0x37, 0x38, 0x39, + 0x34, 0x35, 0x32, 0x65, 0x63, 0x62, 0x32, 0x30, + 0x32, 0x35, 0x33, 0x66, 0x62, 0x61, 0x34, 0x30, + 0x64, 0x62, 0x65, 0x38, 0x35, 0x22, 0x3a, 0x7b, + 0x22, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, + 0x22, 0x3a, 0x22, 0x30, 0x78, 0x33, 0x33, 0x62, + 0x32, 0x65, 0x33, 0x63, 0x39, 0x66, 0x64, 0x30, + 0x38, 0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x22, 0x7d, 0x7d, 0x2c, + 0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, + 0x3a, 0x22, 0x30, 0x78, 0x30, 0x22, 0x2c, 0x22, + 0x67, 0x61, 0x73, 0x55, 0x73, 0x65, 0x64, 0x22, + 0x3a, 0x22, 0x30, 0x78, 0x30, 0x22, 0x2c, 0x22, + 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x48, 0x61, + 0x73, 0x68, 0x22, 0x3a, 0x22, 0x30, 0x78, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x22, + 0x7d, + }, } ) diff --git a/genesis/genesis.go b/genesis/genesis.go index f3c752e..4cad047 100644 --- a/genesis/genesis.go +++ b/genesis/genesis.go @@ -6,14 +6,8 @@ package genesis import ( "errors" "fmt" - "math/big" "time" - "github.com/ava-labs/coreth/core" - - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/params" - "github.com/ava-labs/gecko/ids" "github.com/ava-labs/gecko/utils/formatting" "github.com/ava-labs/gecko/utils/json" @@ -21,7 +15,6 @@ import ( "github.com/ava-labs/gecko/utils/wrappers" "github.com/ava-labs/gecko/vms/avm" "github.com/ava-labs/gecko/vms/components/codec" - "github.com/ava-labs/gecko/vms/evm" "github.com/ava-labs/gecko/vms/nftfx" "github.com/ava-labs/gecko/vms/platformvm" "github.com/ava-labs/gecko/vms/propertyfx" @@ -31,6 +24,11 @@ import ( "github.com/ava-labs/gecko/vms/timestampvm" ) +// ID of the EVM VM +var ( + EVMID = ids.NewID([32]byte{'e', 'v', 'm'}) +) + // Genesis returns the genesis data of the Platform Chain. // Since an AVA network has exactly one Platform Chain, and the Platform Chain // defines the genesis state of the network (who is staking, which chains exist, @@ -76,50 +74,6 @@ func FromConfig(networkID uint32, config *Config) ([]byte, error) { avmSS := avm.StaticService{} err := avmSS.BuildGenesis(nil, &avmArgs, &avmReply) - if err != nil { - panic(err) - } - - // Specify the genesis state of Athereum (the built-in instance of the EVM) - evmBalance, success := new(big.Int).SetString("33b2e3c9fd0804000000000", 16) - if success != true { - return nil, errors.New("problem creating evm genesis state") - } - - alloc := core.GenesisAlloc{} - for _, addr := range config.FundedEVMAddresses { - alloc[common.HexToAddress(addr)] = core.GenesisAccount{ - Balance: evmBalance, - } - } - evmArgs := core.Genesis{ - Config: ¶ms.ChainConfig{ - ChainID: big.NewInt(43110), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: big.NewInt(0), - DAOForkSupport: true, - EIP150Block: big.NewInt(0), - EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - }, - Nonce: 0, - Timestamp: 0, - ExtraData: []byte{0}, - GasLimit: 100000000, - Difficulty: big.NewInt(0), - Mixhash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), - Coinbase: common.HexToAddress("0x0000000000000000000000000000000000000000"), - Alloc: alloc, - Number: 0, - GasUsed: 0, - ParentHash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), - } - evmSS := evm.StaticService{} - evmReply, err := evmSS.BuildGenesis(nil, &evmArgs) if err != nil { return nil, err } @@ -214,9 +168,9 @@ func FromConfig(networkID uint32, config *Config) ([]byte, error) { Name: "X-Chain", }, platformvm.APIChain{ - GenesisData: evmReply, + GenesisData: formatting.CB58{Bytes: config.EVMBytes}, SubnetID: platformvm.DefaultSubnetID, - VMID: evm.ID, + VMID: EVMID, Name: "C-Chain", }, platformvm.APIChain{ diff --git a/genesis/genesis_test.go b/genesis/genesis_test.go index 31aea89..825d07b 100644 --- a/genesis/genesis_test.go +++ b/genesis/genesis_test.go @@ -8,7 +8,6 @@ import ( "github.com/ava-labs/gecko/ids" "github.com/ava-labs/gecko/vms/avm" - "github.com/ava-labs/gecko/vms/evm" "github.com/ava-labs/gecko/vms/platformvm" "github.com/ava-labs/gecko/vms/spchainvm" "github.com/ava-labs/gecko/vms/spdagvm" @@ -97,7 +96,7 @@ func TestAliases(t *testing.T) { t.Fatalf("Should have a custom alias from the vm") } else if _, exists := generalAliases["vm/"+avm.ID.String()]; !exists { t.Fatalf("Should have a custom alias from the vm") - } else if _, exists := generalAliases["vm/"+evm.ID.String()]; !exists { + } else if _, exists := generalAliases["vm/"+EVMID.String()]; !exists { t.Fatalf("Should have a custom alias from the vm") } else if _, exists := generalAliases["vm/"+spdagvm.ID.String()]; !exists { t.Fatalf("Should have a custom alias from the vm") @@ -135,12 +134,12 @@ func TestVMGenesis(t *testing.T) { }, { networkID: CascadeID, - vmID: evm.ID, + vmID: EVMID, expectedID: "2mUYSXfLrDtigwbzj1LxKVsHwELghc5sisoXrzJwLqAAQHF4i", }, { networkID: LocalID, - vmID: evm.ID, + vmID: EVMID, expectedID: "tZGm6RCkeGpVETUTp11DW3UYFZmm69zfqxchpHrSF7wgy8rmw", }, } diff --git a/main/main.go b/main/main.go index db293b5..fc7ae99 100644 --- a/main/main.go +++ b/main/main.go @@ -7,10 +7,10 @@ import ( "fmt" "path" + "github.com/ava-labs/gecko/nat" "github.com/ava-labs/gecko/node" "github.com/ava-labs/gecko/utils/crypto" "github.com/ava-labs/gecko/utils/logging" - "github.com/ava-labs/go-ethereum/p2p/nat" ) // main is the primary entry point to Ava. This can either create a CLI to an @@ -61,26 +61,11 @@ func main() { log.Warn("assertions are enabled. This may slow down execution") } - natChan := make(chan struct{}) - defer close(natChan) + mapper := nat.NewDefaultMapper(log, Config.Nat, nat.TCP, "gecko") + defer mapper.UnmapAllPorts() - go nat.Map( - /*nat=*/ Config.Nat, - /*closeChannel=*/ natChan, - /*protocol=*/ "TCP", - /*internetPort=*/ int(Config.StakingIP.Port), - /*localPort=*/ int(Config.StakingIP.Port), - /*name=*/ "Gecko Staking Server", - ) - - go nat.Map( - /*nat=*/ Config.Nat, - /*closeChannel=*/ natChan, - /*protocol=*/ "TCP", - /*internetPort=*/ int(Config.HTTPPort), - /*localPort=*/ int(Config.HTTPPort), - /*name=*/ "Gecko HTTP Server", - ) + mapper.MapPort(Config.StakingIP.Port, Config.StakingIP.Port) + mapper.MapPort(Config.HTTPPort, Config.HTTPPort) log.Debug("initializing node state") // MainNode is a global variable in the node.go file diff --git a/main/params.go b/main/params.go index 0fafe87..b17b5cd 100644 --- a/main/params.go +++ b/main/params.go @@ -12,12 +12,11 @@ import ( "path" "strings" - "github.com/ava-labs/go-ethereum/p2p/nat" - "github.com/ava-labs/gecko/database/leveldb" "github.com/ava-labs/gecko/database/memdb" "github.com/ava-labs/gecko/genesis" "github.com/ava-labs/gecko/ids" + "github.com/ava-labs/gecko/nat" "github.com/ava-labs/gecko/node" "github.com/ava-labs/gecko/snow/networking/router" "github.com/ava-labs/gecko/utils" @@ -90,6 +89,9 @@ func init() { fs.StringVar(&Config.StakingKeyFile, "staking-tls-key-file", "keys/staker.key", "TLS private key file for staking connections") fs.StringVar(&Config.StakingCertFile, "staking-tls-cert-file", "keys/staker.crt", "TLS certificate file for staking connections") + // Plugins: + fs.StringVar(&Config.PluginDir, "plugin-dir", "./build/plugins", "Plugin directory for Ava VMs") + // Logging: logsDir := fs.String("log-dir", "", "Logging directory for Ava") logLevel := fs.String("log-level", "info", "The log level. Should be one of {verbo, debug, info, warn, error, fatal, off}") @@ -141,12 +143,12 @@ func init() { Config.DB = memdb.New() } - Config.Nat = nat.Any() + Config.Nat = nat.NewRouter() var ip net.IP // If public IP is not specified, get it using shell command dig if *consensusIP == "" { - ip, err = Config.Nat.ExternalIP() + ip, err = Config.Nat.IP() errs.Add(fmt.Errorf( "%s\n"+ "If you are trying to create a local network, try adding --public-ip=127.0.0.1\n"+ diff --git a/nat/mapper.go b/nat/mapper.go new file mode 100644 index 0000000..3beaedd --- /dev/null +++ b/nat/mapper.go @@ -0,0 +1,143 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package nat + +import ( + "sync" + "time" + + "github.com/ava-labs/gecko/utils/logging" + "github.com/ava-labs/gecko/utils/wrappers" +) + +const ( + defaultMappingTimeout = 30 * time.Minute + defaultMappingUpdateInterval = 3 * defaultMappingTimeout / 4 +) + +// Mapper maps port +type Mapper interface { + MapPort(newInternalPort, newExternalPort uint16) error + UnmapAllPorts() error +} + +type mapper struct { + log logging.Logger + router Router + networkProtocol NetworkProtocol + mappingNames string + mappingTimeout time.Duration + mappingUpdateInterval time.Duration + + closer chan struct{} + wg sync.WaitGroup + errLock sync.Mutex + errs wrappers.Errs +} + +// NewMapper returns a new mapper that can map ports on a router +func NewMapper( + log logging.Logger, + router Router, + networkProtocol NetworkProtocol, + mappingNames string, + mappingTimeout time.Duration, + mappingUpdateInterval time.Duration, +) Mapper { + return &mapper{ + log: log, + router: router, + networkProtocol: networkProtocol, + mappingNames: mappingNames, + mappingTimeout: mappingTimeout, + mappingUpdateInterval: mappingUpdateInterval, + closer: make(chan struct{}), + } +} + +// NewDefaultMapper returns a new mapper that can map ports on a router with +// default settings +func NewDefaultMapper( + log logging.Logger, + router Router, + networkProtocol NetworkProtocol, + mappingNames string, +) Mapper { + return NewMapper( + log, + router, + networkProtocol, + mappingNames, + defaultMappingTimeout, // uses the default value + defaultMappingUpdateInterval, // uses the default value + ) +} + +// MapPort maps a local port to a port on the router until UnmapAllPorts is +// called. +func (m *mapper) MapPort(newInternalPort, newExternalPort uint16) error { + m.wg.Add(1) + go m.mapPort(newInternalPort, newExternalPort) + return nil +} + +func (m *mapper) mapPort(newInternalPort, newExternalPort uint16) { + // duration is set to 0 here so that the select case will execute + // immediately + updateTimer := time.NewTimer(0) + defer func() { + updateTimer.Stop() + + m.errLock.Lock() + m.errs.Add(m.router.UnmapPort( + m.networkProtocol, + newInternalPort, + newExternalPort)) + m.errLock.Unlock() + + m.log.Debug("Unmapped external port %d to internal port %d", + newExternalPort, + newInternalPort) + + m.wg.Done() + }() + + for { + select { + case <-updateTimer.C: + err := m.router.MapPort( + m.networkProtocol, + newInternalPort, + newExternalPort, + m.mappingNames, + m.mappingTimeout) + + if err != nil { + m.errLock.Lock() + m.errs.Add(err) + m.errLock.Unlock() + + m.log.Debug("Failed to add mapping from external port %d to internal port %d due to %s", + newExternalPort, + newInternalPort, + err) + } else { + m.log.Debug("Mapped external port %d to internal port %d", + newExternalPort, + newInternalPort) + } + + // remap the port in m.mappingUpdateInterval + updateTimer.Reset(m.mappingUpdateInterval) + case _, _ = <-m.closer: + return // only return when all ports are unmapped + } + } +} + +func (m *mapper) UnmapAllPorts() error { + close(m.closer) + m.wg.Wait() + return m.errs.Err +} diff --git a/nat/no_router.go b/nat/no_router.go new file mode 100644 index 0000000..edb86b6 --- /dev/null +++ b/nat/no_router.go @@ -0,0 +1,28 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package nat + +import ( + "errors" + "net" + "time" +) + +var ( + errNoRouter = errors.New("no nat enabled router was discovered") +) + +type noRouter struct{} + +func (noRouter) MapPort(_ NetworkProtocol, _, _ uint16, _ string, _ time.Duration) error { + return errNoRouter +} + +func (noRouter) UnmapPort(_ NetworkProtocol, _, _ uint16) error { + return errNoRouter +} + +func (noRouter) IP() (net.IP, error) { + return nil, errNoRouter +} diff --git a/nat/pmp.go b/nat/pmp.go new file mode 100644 index 0000000..311375d --- /dev/null +++ b/nat/pmp.go @@ -0,0 +1,71 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package nat + +import ( + "net" + "time" + + "github.com/jackpal/gateway" + "github.com/jackpal/go-nat-pmp" +) + +var ( + pmpClientTimeout = 500 * time.Millisecond +) + +// natPMPClient adapts the NAT-PMP protocol implementation so it conforms to +// the common interface. +type pmpClient struct { + client *natpmp.Client +} + +func (pmp *pmpClient) MapPort( + networkProtocol NetworkProtocol, + newInternalPort uint16, + newExternalPort uint16, + mappingName string, + mappingDuration time.Duration) error { + protocol := string(networkProtocol) + internalPort := int(newInternalPort) + externalPort := int(newExternalPort) + // go-nat-pmp uses seconds to denote their lifetime + lifetime := int(mappingDuration / time.Second) + + _, err := pmp.client.AddPortMapping(protocol, internalPort, externalPort, lifetime) + return err +} + +func (pmp *pmpClient) UnmapPort( + networkProtocol NetworkProtocol, + internalPort uint16, + _ uint16) error { + protocol := string(networkProtocol) + internalPortInt := int(internalPort) + + _, err := pmp.client.AddPortMapping(protocol, internalPortInt, 0, 0) + return err +} + +func (pmp *pmpClient) IP() (net.IP, error) { + response, err := pmp.client.GetExternalAddress() + if err != nil { + return nil, err + } + return response.ExternalIPAddress[:], nil +} + +func getPMPRouter() Router { + gatewayIP, err := gateway.DiscoverGateway() + if err != nil { + return nil + } + + pmp := &pmpClient{natpmp.NewClientWithTimeout(gatewayIP, pmpClientTimeout)} + if _, err := pmp.IP(); err != nil { + return nil + } + + return pmp +} diff --git a/nat/router.go b/nat/router.go new file mode 100644 index 0000000..11b58f9 --- /dev/null +++ b/nat/router.go @@ -0,0 +1,65 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +// Package nat performs network address translation and provides helpers for +// routing ports. +package nat + +import ( + "net" + "time" +) + +// NetworkProtocol is a protocol that will be used through a port +type NetworkProtocol string + +// Available protocol +const ( + TCP NetworkProtocol = "TCP" + UDP NetworkProtocol = "UDP" +) + +// Router provides a standard NAT router functions. Specifically, allowing the +// fetching of public IPs and port forwarding to this computer. +type Router interface { + // mapPort creates a mapping between a port on the local computer to an + // external port on the router. + // + // The mappingName is something displayed on the router, so it is included + // for completeness. + MapPort( + networkProtocol NetworkProtocol, + newInternalPort uint16, + newExternalPort uint16, + mappingName string, + mappingDuration time.Duration) error + + // UnmapPort clears a mapping that was previous made by a call to MapPort + UnmapPort( + networkProtocol NetworkProtocol, + internalPort uint16, + externalPort uint16) error + + // Returns the routers IP address on the network the router considers + // external + IP() (net.IP, error) +} + +// NewRouter returns a new router discovered on the local network +func NewRouter() Router { + routers := make(chan Router) + // Because getting a router can take a noticeable amount of time to error, + // we run these requests in parallel + go func() { + routers <- getUPnPRouter() + }() + go func() { + routers <- getPMPRouter() + }() + for i := 0; i < 2; i++ { + if router := <-routers; router != nil { + return router + } + } + return noRouter{} +} diff --git a/nat/upnp.go b/nat/upnp.go new file mode 100644 index 0000000..e60cd6e --- /dev/null +++ b/nat/upnp.go @@ -0,0 +1,253 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package nat + +import ( + "errors" + "fmt" + "net" + "time" + + "github.com/huin/goupnp" + "github.com/huin/goupnp/dcps/internetgateway1" + "github.com/huin/goupnp/dcps/internetgateway2" +) + +const ( + soapTimeout = time.Second +) + +var ( + errNoGateway = errors.New("Failed to connect to any avaliable gateways") +) + +// upnpClient is the interface used by goupnp for their client implementations +type upnpClient interface { + // attempts to map connection using the provided protocol from the external + // port to the internal port for the lease duration. + AddPortMapping( + newRemoteHost string, + newExternalPort uint16, + newProtocol string, + newInternalPort uint16, + newInternalClient string, + newEnabled bool, + newPortMappingDescription string, + newLeaseDuration uint32) error + + // attempt to remove any mapping from the external port. + DeletePortMapping( + newRemoteHost string, + newExternalPort uint16, + newProtocol string) error + + // attempts to return the external IP address, formatted as a string. + GetExternalIPAddress() (ip string, err error) + + // returns if there is rsip available, nat enabled, or an unexpected error. + GetNATRSIPStatus() (newRSIPAvailable bool, natEnabled bool, err error) +} + +type upnpRouter struct { + root *goupnp.RootDevice + client upnpClient +} + +func (n *upnpRouter) MapPort( + networkProtocol NetworkProtocol, + newInternalPort uint16, + newExternalPort uint16, + mappingName string, + mappingDuration time.Duration, +) error { + ip, err := n.localAddress() + if err != nil { + return err + } + + protocol := string(networkProtocol) + // goupnp uses seconds to denote their lifetime + lifetime := uint32(mappingDuration / time.Second) + + // UnmapPort's error is intentionally dropped, because the mapping may not + // exist. + n.UnmapPort(networkProtocol, newInternalPort, newExternalPort) + + return n.client.AddPortMapping( + "", // newRemoteHost isn't used to limit the mapping to a host + newExternalPort, + protocol, + newInternalPort, + ip.String(), // newInternalClient is the client traffic should be sent to + true, // newEnabled enables port mappings + mappingName, + lifetime, + ) +} + +func (n *upnpRouter) UnmapPort(networkProtocol NetworkProtocol, _, externalPort uint16) error { + protocol := string(networkProtocol) + return n.client.DeletePortMapping( + "", // newRemoteHost isn't used to limit the mapping to a host + externalPort, + protocol) +} + +func (n *upnpRouter) IP() (net.IP, error) { + ipStr, err := n.client.GetExternalIPAddress() + if err != nil { + return nil, err + } + + ip := net.ParseIP(ipStr) + if ip == nil { + return nil, fmt.Errorf("invalid IP %s", ipStr) + } + return ip, nil +} + +func (n *upnpRouter) localAddress() (net.IP, error) { + // attempt to get an address on the router + deviceAddr, err := net.ResolveUDPAddr("udp4", n.root.URLBase.Host) + if err != nil { + return nil, err + } + deviceIP := deviceAddr.IP + + netInterfaces, err := net.Interfaces() + if err != nil { + return nil, err + } + + // attempt to find one of my ips that the router would know about + for _, netInterface := range netInterfaces { + addrs, err := netInterface.Addrs() + if err != nil { + continue + } + + for _, addr := range addrs { + // this is pretty janky, but it seems to be the best way to get the + // ip mask and properly check if the ip references the device we are + // connected to + ipNet, ok := addr.(*net.IPNet) + if !ok { + continue + } + + if ipNet.Contains(deviceIP) { + return ipNet.IP, nil + } + } + } + return nil, fmt.Errorf("couldn't find the local address in the same network as %s", deviceIP) +} + +// getUPnPRouter searches for all Gateway Devices that have avaliable +// connections in the goupnp library and returns the first connection it can +// find. +func getUPnPRouter() Router { + routers := make(chan *upnpRouter) + // Because DiscoverDevices takes a noticeable amount of time to error, we + // run these requests in parallel + go func() { + routers <- connectToGateway(internetgateway1.URN_WANConnectionDevice_1, gateway1) + }() + go func() { + routers <- connectToGateway(internetgateway2.URN_WANConnectionDevice_2, gateway2) + }() + for i := 0; i < 2; i++ { + if router := <-routers; router != nil { + return router + } + } + return nil +} + +func gateway1(client goupnp.ServiceClient) upnpClient { + switch client.Service.ServiceType { + case internetgateway1.URN_WANIPConnection_1: + return &internetgateway1.WANIPConnection1{ServiceClient: client} + case internetgateway1.URN_WANPPPConnection_1: + return &internetgateway1.WANPPPConnection1{ServiceClient: client} + default: + return nil + } +} + +func gateway2(client goupnp.ServiceClient) upnpClient { + switch client.Service.ServiceType { + case internetgateway2.URN_WANIPConnection_1: + return &internetgateway2.WANIPConnection1{ServiceClient: client} + case internetgateway2.URN_WANIPConnection_2: + return &internetgateway2.WANIPConnection2{ServiceClient: client} + case internetgateway2.URN_WANPPPConnection_1: + return &internetgateway2.WANPPPConnection1{ServiceClient: client} + default: + return nil + } +} + +func connectToGateway(deviceType string, toClient func(goupnp.ServiceClient) upnpClient) *upnpRouter { + devs, err := goupnp.DiscoverDevices(deviceType) + if err != nil { + return nil + } + // we are iterating over all the network devices, acting a possible roots + for i := range devs { + dev := &devs[i] + if dev.Root == nil { + continue + } + + // the root device may be a router, so attempt to connect to that + rootDevice := &dev.Root.Device + if upnp := getRouter(dev, rootDevice, toClient); upnp != nil { + return upnp + } + + // attempt to connect to any sub devices + devices := rootDevice.Devices + for i := range devices { + if upnp := getRouter(dev, &devices[i], toClient); upnp != nil { + return upnp + } + } + } + return nil +} + +func getRouter(rootDevice *goupnp.MaybeRootDevice, device *goupnp.Device, toClient func(goupnp.ServiceClient) upnpClient) *upnpRouter { + for i := range device.Services { + service := &device.Services[i] + + soapClient := service.NewSOAPClient() + // make sure the client times out if needed + soapClient.HTTPClient.Timeout = soapTimeout + + // attempt to create a client connection + serviceClient := goupnp.ServiceClient{ + SOAPClient: soapClient, + RootDevice: rootDevice.Root, + Location: rootDevice.Location, + Service: service, + } + client := toClient(serviceClient) + if client == nil { + continue + } + + // check whether port mapping is enabled + if _, nat, err := client.GetNATRSIPStatus(); err != nil || !nat { + continue + } + + // we found a router! + return &upnpRouter{ + root: rootDevice.Root, + client: client, + } + } + return nil +} diff --git a/node/config.go b/node/config.go index 76c9e48..b35d997 100644 --- a/node/config.go +++ b/node/config.go @@ -4,9 +4,8 @@ package node import ( - "github.com/ava-labs/go-ethereum/p2p/nat" - "github.com/ava-labs/gecko/database" + "github.com/ava-labs/gecko/nat" "github.com/ava-labs/gecko/snow/consensus/avalanche" "github.com/ava-labs/gecko/snow/networking/router" "github.com/ava-labs/gecko/utils" @@ -16,7 +15,7 @@ import ( // Config contains all of the configurations of an Ava node. type Config struct { // protocol to use for opening the network interface - Nat nat.Interface + Nat nat.Router // ID of the network this node should connect to NetworkID uint32 @@ -56,6 +55,9 @@ type Config struct { // Logging configuration LoggingConfig logging.Config + // Plugin directory + PluginDir string + // Consensus configuration ConsensusParams avalanche.Parameters diff --git a/node/node.go b/node/node.go index caded55..9257ca7 100644 --- a/node/node.go +++ b/node/node.go @@ -14,6 +14,7 @@ import ( "errors" "fmt" "io/ioutil" + "path" "sync" "unsafe" @@ -39,10 +40,10 @@ import ( "github.com/ava-labs/gecko/utils/wrappers" "github.com/ava-labs/gecko/vms" "github.com/ava-labs/gecko/vms/avm" - "github.com/ava-labs/gecko/vms/evm" "github.com/ava-labs/gecko/vms/nftfx" "github.com/ava-labs/gecko/vms/platformvm" "github.com/ava-labs/gecko/vms/propertyfx" + "github.com/ava-labs/gecko/vms/rpcchainvm" "github.com/ava-labs/gecko/vms/secp256k1fx" "github.com/ava-labs/gecko/vms/spchainvm" "github.com/ava-labs/gecko/vms/spdagvm" @@ -359,7 +360,7 @@ func (n *Node) initNodeID() error { } // Create the vmManager and register the following vms: -// AVM, EVM, Simple Payments DAG, Simple Payments Chain +// AVM, Simple Payments DAG, Simple Payments Chain // The Platform VM is registered in initStaking because // its factory needs to reference n.chainManager, which is nil right now func (n *Node) initVMManager() error { @@ -376,7 +377,7 @@ func (n *Node) initVMManager() error { AVA: avaAssetID, Platform: ids.Empty, }), - n.vmManager.RegisterVMFactory(evm.ID, &evm.Factory{}), + n.vmManager.RegisterVMFactory(genesis.EVMID, &rpcchainvm.Factory{Path: path.Join(n.Config.PluginDir, "evm")}), n.vmManager.RegisterVMFactory(spdagvm.ID, &spdagvm.Factory{TxFee: n.Config.AvaTxFee}), n.vmManager.RegisterVMFactory(spchainvm.ID, &spchainvm.Factory{}), n.vmManager.RegisterVMFactory(timestampvm.ID, ×tampvm.Factory{}), diff --git a/scripts/build.sh b/scripts/build.sh index 6bb31a3..b2d1984 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -3,18 +3,31 @@ # Ted: contact me when you make any changes PREFIX="${PREFIX:-$(pwd)/build}" +PLUGIN_PREFIX="$PREFIX/plugins" SRC_DIR="$(dirname "${BASH_SOURCE[0]}")" source "$SRC_DIR/env.sh" +CORETH_PKG=github.com/ava-labs/coreth +CORETH_PATH="$GOPATH/src/$CORETH_PKG" +if [[ -d "$CORETH_PATH/.git" ]]; then + cd "$CORETH_PATH" + go get -t -v -d "./..." + cd - +else + go get -t -v -d "$CORETH_PKG/..." +fi + GECKO_PKG=github.com/ava-labs/gecko GECKO_PATH="$GOPATH/src/$GECKO_PKG" if [[ -d "$GECKO_PATH/.git" ]]; then cd "$GECKO_PATH" - go get -t -v "./..." + go get -t -v -d "./..." cd - else - go get -t -v "$GECKO_PKG/..." + go get -t -v -d "$GECKO_PKG/..." fi + go build -o "$PREFIX/ava" "$GECKO_PATH/main/"*.go go build -o "$PREFIX/xputtest" "$GECKO_PATH/xputtest/"*.go +go build -o "$PLUGIN_PREFIX/evm" "$CORETH_PATH/plugin/"*.go diff --git a/scripts/build_image.sh b/scripts/build_image.sh index 1b91410..5da7f59 100755 --- a/scripts/build_image.sh +++ b/scripts/build_image.sh @@ -17,8 +17,6 @@ fi if [[ ! -d "$WORKPREFIX" ]]; then mkdir -p "$WORKPREFIX" git config --global credential.helper cache - git clone https://github.com/ava-labs/coreth.git "$WORKPREFIX/coreth" - git clone --depth 1 https://github.com/ava-labs/go-ethereum.git "$WORKPREFIX/go-ethereum" git clone https://github.com/ava-labs/gecko.git "$WORKPREFIX/gecko" fi GECKO_COMMIT="$(git --git-dir="$WORKPREFIX/gecko/.git" rev-parse --short HEAD)" diff --git a/snow/engine/common/http_handler.go b/snow/engine/common/http_handler.go index c6b898d..ca00136 100644 --- a/snow/engine/common/http_handler.go +++ b/snow/engine/common/http_handler.go @@ -8,7 +8,7 @@ import ( ) // LockOption allows the vm to specify their lock option based on their endpoint -type LockOption int +type LockOption uint32 // List of all allowed options const ( diff --git a/snow/engine/common/message.go b/snow/engine/common/message.go index f987902..19f4205 100644 --- a/snow/engine/common/message.go +++ b/snow/engine/common/message.go @@ -10,7 +10,7 @@ import ( // TODO: Consider renaming Message to, say, VMMessage // Message is an enum of the message types that vms can send to consensus -type Message int +type Message uint32 const ( // PendingTxs notifies a consensus engine that diff --git a/utils/crypto/crypto_benchmark_test.go b/utils/crypto/crypto_benchmark_test.go index 2d4d2f9..6262a34 100644 --- a/utils/crypto/crypto_benchmark_test.go +++ b/utils/crypto/crypto_benchmark_test.go @@ -41,7 +41,7 @@ func init() { RSA: &FactoryRSA{}, RSAPSS: &FactoryRSAPSS{}, ED25519: &FactoryED25519{}, - SECP256K1: &FactorySECP256K1{}, + SECP256K1: &FactorySECP256K1R{}, } for _, f := range factories { fKeys := []PublicKey{} diff --git a/utils/crypto/secp256k1.go b/utils/crypto/secp256k1.go deleted file mode 100644 index b9fa41a..0000000 --- a/utils/crypto/secp256k1.go +++ /dev/null @@ -1,149 +0,0 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package crypto - -import ( - "crypto/ecdsa" - "crypto/rand" - "math/big" - - "github.com/ava-labs/go-ethereum/crypto" - "github.com/ava-labs/go-ethereum/crypto/secp256k1" - - "github.com/ava-labs/gecko/ids" - "github.com/ava-labs/gecko/utils/hashing" -) - -const ( - // SECP256K1SigLen is the number of bytes in a secp2561k signature - SECP256K1SigLen = 64 - - // SECP256K1SKLen is the number of bytes in a secp2561k private key - SECP256K1SKLen = 32 - - // SECP256K1PKLen is the number of bytes in a secp2561k public key - SECP256K1PKLen = 33 -) - -// FactorySECP256K1 ... -type FactorySECP256K1 struct{} - -// NewPrivateKey implements the Factory interface -func (*FactorySECP256K1) NewPrivateKey() (PrivateKey, error) { - k, err := ecdsa.GenerateKey(secp256k1.S256(), rand.Reader) - if err != nil { - return nil, err - } - return &PrivateKeySECP256K1{sk: k}, nil -} - -// ToPublicKey implements the Factory interface -func (*FactorySECP256K1) ToPublicKey(b []byte) (PublicKey, error) { - key, err := crypto.DecompressPubkey(b) - return &PublicKeySECP256K1{ - pk: key, - bytes: b, - }, err -} - -// ToPrivateKey implements the Factory interface -func (*FactorySECP256K1) ToPrivateKey(b []byte) (PrivateKey, error) { - key, err := crypto.ToECDSA(b) - return &PrivateKeySECP256K1{ - sk: key, - bytes: b, - }, err -} - -// PublicKeySECP256K1 ... -type PublicKeySECP256K1 struct { - pk *ecdsa.PublicKey - addr ids.ShortID - bytes []byte -} - -// Verify implements the PublicKey interface -func (k *PublicKeySECP256K1) Verify(msg, sig []byte) bool { - return k.VerifyHash(hashing.ComputeHash256(msg), sig) -} - -// VerifyHash implements the PublicKey interface -func (k *PublicKeySECP256K1) VerifyHash(hash, sig []byte) bool { - if verifySECP256K1SignatureFormat(sig) != nil { - return false - } - return crypto.VerifySignature(k.Bytes(), hash, sig) -} - -// Address implements the PublicKey interface -func (k *PublicKeySECP256K1) Address() ids.ShortID { - if k.addr.IsZero() { - addr, err := ids.ToShortID(hashing.PubkeyBytesToAddress(k.Bytes())) - if err != nil { - panic(err) - } - k.addr = addr - } - return k.addr -} - -// Bytes implements the PublicKey interface -func (k *PublicKeySECP256K1) Bytes() []byte { - if k.bytes == nil { - k.bytes = crypto.CompressPubkey(k.pk) - } - return k.bytes -} - -// PrivateKeySECP256K1 ... -type PrivateKeySECP256K1 struct { - sk *ecdsa.PrivateKey - pk *PublicKeySECP256K1 - bytes []byte -} - -// PublicKey implements the PrivateKey interface -func (k *PrivateKeySECP256K1) PublicKey() PublicKey { - if k.pk == nil { - k.pk = &PublicKeySECP256K1{pk: (*ecdsa.PublicKey)(&k.sk.PublicKey)} - } - return k.pk -} - -// Sign implements the PrivateKey interface -func (k *PrivateKeySECP256K1) Sign(msg []byte) ([]byte, error) { - return k.SignHash(hashing.ComputeHash256(msg)) -} - -// SignHash implements the PrivateKey interface -func (k *PrivateKeySECP256K1) SignHash(hash []byte) ([]byte, error) { - sig, err := crypto.Sign(hash, k.sk) - if err != nil { - return nil, err - } - return sig[:len(sig)-1], err -} - -// Bytes implements the PrivateKey interface -func (k *PrivateKeySECP256K1) Bytes() []byte { - if k.bytes == nil { - k.bytes = make([]byte, SECP256K1SKLen) - bytes := k.sk.D.Bytes() - copy(k.bytes[SECP256K1SKLen-len(bytes):], bytes) - } - return k.bytes -} - -func verifySECP256K1SignatureFormat(sig []byte) error { - if len(sig) != SECP256K1SigLen { - return errInvalidSigLen - } - var r, s big.Int - r.SetBytes(sig[:32]) - s.SetBytes(sig[32:]) - if !crypto.ValidateSignatureValues(0, &r, &s, true) { - return errMutatedSig - } - return nil -} diff --git a/utils/crypto/secp256k1_recover_benchmark_test.go b/utils/crypto/secp256k1_recover_benchmark_test.go deleted file mode 100644 index d1a3530..0000000 --- a/utils/crypto/secp256k1_recover_benchmark_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package crypto - -import ( - "testing" - - "github.com/ava-labs/gecko/utils/hashing" -) - -// NumRecoveries is the number of recoveries to run per operation -const NumRecoveries = 1 - -var ( - secpSigs [][]byte -) - -func init() { - factory := FactorySECP256K1R{} - - hash := hashing.ComputeHash256(nil) - for i := byte(0); i < NumRecoveries; i++ { - key, err := factory.NewPrivateKey() - if err != nil { - panic(err) - } - sig, err := key.SignHash(hash) - if err != nil { - panic(err) - } - secpSigs = append(secpSigs, sig) - } -} - -func recover() { - factory := FactorySECP256K1R{} - hash := hashing.ComputeHash256(nil) - for _, sig := range secpSigs { - if _, err := factory.RecoverHashPublicKey(hash, sig); err != nil { - panic(err) - } - } -} - -// BenchmarkSecp256k1RecoverVerify runs the benchmark with secp sig -func BenchmarkSecp256k1RecoverVerify(b *testing.B) { - for n := 0; n < b.N; n++ { - recover() - } -} diff --git a/utils/crypto/secp256k1r.go b/utils/crypto/secp256k1r.go index ef50618..1fde767 100644 --- a/utils/crypto/secp256k1r.go +++ b/utils/crypto/secp256k1r.go @@ -5,13 +5,11 @@ package crypto import ( "bytes" - "crypto/ecdsa" - "crypto/rand" - "math/big" + "errors" "sort" - "github.com/ava-labs/go-ethereum/crypto" - "github.com/ava-labs/go-ethereum/crypto/secp256k1" + "github.com/decred/dcrd/dcrec/secp256k1" + "github.com/decred/dcrd/dcrec/secp256k1/ecdsa" "github.com/ava-labs/gecko/cache" "github.com/ava-labs/gecko/ids" @@ -31,6 +29,14 @@ const ( // SECP256K1RPKLen is the number of bytes in a secp2561k recoverable public // key SECP256K1RPKLen = 33 + + // from the decred library: + // compactSigMagicOffset is a value used when creating the compact signature + // recovery code inherited from Bitcoin and has no meaning, but has been + // retained for compatibility. For historical purposes, it was originally + // picked to avoid a binary representation that would allow compact + // signatures to be mistaken for other components. + compactSigMagicOffset = 27 ) // FactorySECP256K1R ... @@ -38,16 +44,13 @@ type FactorySECP256K1R struct{ Cache cache.LRU } // NewPrivateKey implements the Factory interface func (*FactorySECP256K1R) NewPrivateKey() (PrivateKey, error) { - k, err := ecdsa.GenerateKey(secp256k1.S256(), rand.Reader) - if err != nil { - return nil, err - } - return &PrivateKeySECP256K1R{sk: k}, nil + k, err := secp256k1.GeneratePrivateKey() + return &PrivateKeySECP256K1R{sk: k}, err } // ToPublicKey implements the Factory interface func (*FactorySECP256K1R) ToPublicKey(b []byte) (PublicKey, error) { - key, err := crypto.DecompressPubkey(b) + key, err := secp256k1.ParsePubKey(b) return &PublicKeySECP256K1R{ pk: key, bytes: b, @@ -56,11 +59,10 @@ func (*FactorySECP256K1R) ToPublicKey(b []byte) (PublicKey, error) { // ToPrivateKey implements the Factory interface func (*FactorySECP256K1R) ToPrivateKey(b []byte) (PrivateKey, error) { - key, err := crypto.ToECDSA(b) return &PrivateKeySECP256K1R{ - sk: key, + sk: secp256k1.PrivKeyFromBytes(b), bytes: b, - }, err + }, nil } // RecoverPublicKey returns the public key from a 65 byte signature @@ -75,25 +77,35 @@ func (f *FactorySECP256K1R) RecoverHashPublicKey(hash, sig []byte) (PublicKey, e copy(cacheBytes[len(hash):], sig) id := ids.NewID(hashing.ComputeHash256Array(cacheBytes)) if cachedPublicKey, ok := f.Cache.Get(id); ok { - return cachedPublicKey.(*PublicKeySECP256K1), nil + return cachedPublicKey.(*PublicKeySECP256K1R), nil } if err := verifySECP256K1RSignatureFormat(sig); err != nil { return nil, err } - rawPubkey, err := crypto.SigToPub(hash, sig) + sig, err := sigToRawSig(sig) if err != nil { return nil, err } - pubkey := &PublicKeySECP256K1{pk: rawPubkey} + + rawPubkey, compressed, err := ecdsa.RecoverCompact(sig, hash) + if err != nil { + return nil, err + } + + if compressed { + return nil, errors.New("wasn't expecting a compresses key") + } + + pubkey := &PublicKeySECP256K1R{pk: rawPubkey} f.Cache.Put(id, pubkey) return pubkey, nil } // PublicKeySECP256K1R ... type PublicKeySECP256K1R struct { - pk *ecdsa.PublicKey + pk *secp256k1.PublicKey addr ids.ShortID bytes []byte } @@ -105,10 +117,12 @@ func (k *PublicKeySECP256K1R) Verify(msg, sig []byte) bool { // VerifyHash implements the PublicKey interface func (k *PublicKeySECP256K1R) VerifyHash(hash, sig []byte) bool { - if verifySECP256K1RSignatureFormat(sig) != nil { + factory := FactorySECP256K1R{} + pk, err := factory.RecoverHashPublicKey(hash, sig) + if err != nil { return false } - return crypto.VerifySignature(k.Bytes(), hash, sig[:SECP256K1RSigLen-1]) + return k.Address().Equals(pk.Address()) } // Address implements the PublicKey interface @@ -126,14 +140,14 @@ func (k *PublicKeySECP256K1R) Address() ids.ShortID { // Bytes implements the PublicKey interface func (k *PublicKeySECP256K1R) Bytes() []byte { if k.bytes == nil { - k.bytes = crypto.CompressPubkey(k.pk) + k.bytes = k.pk.SerializeCompressed() } return k.bytes } // PrivateKeySECP256K1R ... type PrivateKeySECP256K1R struct { - sk *ecdsa.PrivateKey + sk *secp256k1.PrivateKey pk *PublicKeySECP256K1R bytes []byte } @@ -141,7 +155,7 @@ type PrivateKeySECP256K1R struct { // PublicKey implements the PrivateKey interface func (k *PrivateKeySECP256K1R) PublicKey() PublicKey { if k.pk == nil { - k.pk = &PublicKeySECP256K1R{pk: (*ecdsa.PublicKey)(&k.sk.PublicKey)} + k.pk = &PublicKeySECP256K1R{pk: k.sk.PubKey()} } return k.pk } @@ -153,27 +167,49 @@ func (k *PrivateKeySECP256K1R) Sign(msg []byte) ([]byte, error) { // SignHash implements the PrivateKey interface func (k *PrivateKeySECP256K1R) SignHash(hash []byte) ([]byte, error) { - return crypto.Sign(hash, k.sk) + sig := ecdsa.SignCompact(k.sk, hash, false) // returns [v || r || s] + return rawSigToSig(sig) } // Bytes implements the PrivateKey interface func (k *PrivateKeySECP256K1R) Bytes() []byte { if k.bytes == nil { - k.bytes = make([]byte, SECP256K1RSKLen) - bytes := k.sk.D.Bytes() - copy(k.bytes[SECP256K1RSKLen-len(bytes):], bytes) + k.bytes = k.sk.Serialize() } return k.bytes } +// raw sig has format [v || r || s] whereas the sig has format [r || s || v] +func rawSigToSig(sig []byte) ([]byte, error) { + if len(sig) != SECP256K1RSigLen { + return nil, errInvalidSigLen + } + recCode := sig[0] + copy(sig, sig[1:]) + sig[SECP256K1RSigLen-1] = recCode - compactSigMagicOffset + return sig, nil +} + +// sig has format [r || s || v] whereas the raw sig has format [v || r || s] +func sigToRawSig(sig []byte) ([]byte, error) { + if len(sig) != SECP256K1RSigLen { + return nil, errInvalidSigLen + } + newSig := make([]byte, SECP256K1RSigLen) + newSig[0] = sig[SECP256K1RSigLen-1] + compactSigMagicOffset + copy(newSig[1:], sig) + return newSig, nil +} + +// verifies the signature format in format [r || s || v] func verifySECP256K1RSignatureFormat(sig []byte) error { if len(sig) != SECP256K1RSigLen { return errInvalidSigLen } - var r, s big.Int - r.SetBytes(sig[:32]) - s.SetBytes(sig[32:64]) - if !crypto.ValidateSignatureValues(sig[64], &r, &s, true) { + + var s secp256k1.ModNScalar + s.SetByteSlice(sig[32:64]) + if s.IsOverHalfOrder() { return errMutatedSig } return nil diff --git a/utils/crypto/secp256k1r_test.go b/utils/crypto/secp256k1r_test.go index 244b30b..4ed7f75 100644 --- a/utils/crypto/secp256k1r_test.go +++ b/utils/crypto/secp256k1r_test.go @@ -10,6 +10,8 @@ import ( "github.com/ava-labs/gecko/cache" "github.com/ava-labs/gecko/utils/formatting" "github.com/ava-labs/gecko/utils/hashing" + "github.com/decred/dcrd/dcrec/secp256k1" + "github.com/stretchr/testify/assert" ) func TestRecover(t *testing.T) { @@ -73,3 +75,24 @@ func TestGenRecreate(t *testing.T) { } } } + +func TestVerifyMutatedSignature(t *testing.T) { + factory := FactorySECP256K1R{} + + sk, err := factory.NewPrivateKey() + assert.NoError(t, err) + + msg := []byte{'h', 'e', 'l', 'l', 'o'} + + sig, err := sk.Sign(msg) + assert.NoError(t, err) + + var s secp256k1.ModNScalar + s.SetByteSlice(sig[32:64]) + s.Negate() + newSBytes := s.Bytes() + copy(sig[32:], newSBytes[:]) + + _, err = factory.RecoverPublicKey(msg, sig) + assert.Error(t, err) +} diff --git a/vms/avm/factory.go b/vms/avm/factory.go index b8896ad..96865c6 100644 --- a/vms/avm/factory.go +++ b/vms/avm/factory.go @@ -19,9 +19,9 @@ type Factory struct { } // New ... -func (f *Factory) New() interface{} { +func (f *Factory) New() (interface{}, error) { return &VM{ ava: f.AVA, platform: f.Platform, - } + }, nil } diff --git a/vms/avm/vm.go b/vms/avm/vm.go index e6af76d..c8b33f1 100644 --- a/vms/avm/vm.go +++ b/vms/avm/vm.go @@ -198,6 +198,10 @@ func (vm *VM) Initialize( // Shutdown implements the avalanche.DAGVM interface func (vm *VM) Shutdown() { + if vm.timer == nil { + return + } + vm.timer.Stop() if err := vm.baseDB.Close(); err != nil { vm.ctx.Log.Error("Closing the database failed with %s", err) diff --git a/vms/components/core/snowman_vm.go b/vms/components/core/snowman_vm.go index a659b1b..f710edd 100644 --- a/vms/components/core/snowman_vm.go +++ b/vms/components/core/snowman_vm.go @@ -83,6 +83,10 @@ func (svm *SnowmanVM) GetBlock(ID ids.ID) (snowman.Block, error) { // Shutdown this vm func (svm *SnowmanVM) Shutdown() { + if svm.DB == nil { + return + } + svm.DB.Commit() // Flush DB svm.DB.GetDatabase().Close() // close underlying database svm.DB.Close() // close versionDB diff --git a/vms/evm/block.go b/vms/evm/block.go deleted file mode 100644 index ec47490..0000000 --- a/vms/evm/block.go +++ /dev/null @@ -1,75 +0,0 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package evm - -import ( - "fmt" - - "github.com/ava-labs/go-ethereum/core/types" - "github.com/ava-labs/go-ethereum/rlp" - - "github.com/ava-labs/gecko/ids" - "github.com/ava-labs/gecko/snow/choices" - "github.com/ava-labs/gecko/snow/consensus/snowman" -) - -// Block implements the snowman.Block interface -type Block struct { - id ids.ID - ethBlock *types.Block - vm *VM -} - -// ID implements the snowman.Block interface -func (b *Block) ID() ids.ID { return b.id } - -// Accept implements the snowman.Block interface -func (b *Block) Accept() { - b.vm.ctx.Log.Verbo("Block %s is accepted", b.ID()) - b.vm.updateStatus(b.ID(), choices.Accepted) -} - -// Reject implements the snowman.Block interface -func (b *Block) Reject() { - b.vm.ctx.Log.Verbo("Block %s is rejected", b.ID()) - b.vm.updateStatus(b.ID(), choices.Rejected) -} - -// Status implements the snowman.Block interface -func (b *Block) Status() choices.Status { - status := b.vm.getCachedStatus(b.ID()) - if status == choices.Unknown && b.ethBlock != nil { - return choices.Processing - } - return status -} - -// Parent implements the snowman.Block interface -func (b *Block) Parent() snowman.Block { - parentID := ids.NewID(b.ethBlock.ParentHash()) - block := &Block{ - id: parentID, - ethBlock: b.vm.getCachedBlock(parentID), - vm: b.vm, - } - b.vm.ctx.Log.Verbo("Parent(%s) has status: %s", block.ID(), block.Status()) - return block -} - -// Verify implements the snowman.Block interface -func (b *Block) Verify() error { - _, err := b.vm.chain.InsertChain([]*types.Block{b.ethBlock}) - return err -} - -// Bytes implements the snowman.Block interface -func (b *Block) Bytes() []byte { - res, err := rlp.EncodeToBytes(b.ethBlock) - if err != nil { - panic(err) - } - return res -} - -func (b *Block) String() string { return fmt.Sprintf("EVM block, ID = %s", b.ID()) } diff --git a/vms/evm/database.go b/vms/evm/database.go deleted file mode 100644 index de592e1..0000000 --- a/vms/evm/database.go +++ /dev/null @@ -1,66 +0,0 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package evm - -import ( - "errors" - - "github.com/ava-labs/go-ethereum/ethdb" - - "github.com/ava-labs/gecko/database" -) - -var ( - errOpNotSupported = errors.New("this operation is not supported") -) - -// Database implements ethdb.Database -type Database struct{ database.Database } - -// HasAncient returns an error as we don't have a backing chain freezer. -func (db Database) HasAncient(kind string, number uint64) (bool, error) { - return false, errOpNotSupported -} - -// Ancient returns an error as we don't have a backing chain freezer. -func (db Database) Ancient(kind string, number uint64) ([]byte, error) { return nil, errOpNotSupported } - -// Ancients returns an error as we don't have a backing chain freezer. -func (db Database) Ancients() (uint64, error) { return 0, errOpNotSupported } - -// AncientSize returns an error as we don't have a backing chain freezer. -func (db Database) AncientSize(kind string) (uint64, error) { return 0, errOpNotSupported } - -// AppendAncient returns an error as we don't have a backing chain freezer. -func (db Database) AppendAncient(number uint64, hash, header, body, receipts, td []byte) error { - return errOpNotSupported -} - -// TruncateAncients returns an error as we don't have a backing chain freezer. -func (db Database) TruncateAncients(items uint64) error { return errOpNotSupported } - -// Sync returns an error as we don't have a backing chain freezer. -func (db Database) Sync() error { return errOpNotSupported } - -// NewBatch implements ethdb.Database -func (db Database) NewBatch() ethdb.Batch { return Batch{db.Database.NewBatch()} } - -// NewIterator implements ethdb.Database -func (db Database) NewIterator() ethdb.Iterator { return db.Database.NewIterator() } - -// NewIteratorWithPrefix implements ethdb.Database -func (db Database) NewIteratorWithPrefix(prefix []byte) ethdb.Iterator { - return db.NewIteratorWithPrefix(prefix) -} - -// NewIteratorWithStart implements ethdb.Database -func (db Database) NewIteratorWithStart(start []byte) ethdb.Iterator { - return db.NewIteratorWithStart(start) -} - -// Batch implements ethdb.Batch -type Batch struct{ database.Batch } - -// Replay implements ethdb.Batch -func (batch Batch) Replay(w ethdb.KeyValueWriter) error { return batch.Batch.Replay(w) } diff --git a/vms/evm/factory.go b/vms/evm/factory.go deleted file mode 100644 index a4c0eca..0000000 --- a/vms/evm/factory.go +++ /dev/null @@ -1,19 +0,0 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package evm - -import ( - "github.com/ava-labs/gecko/ids" -) - -// ID this VM should be referenced by -var ( - ID = ids.NewID([32]byte{'e', 'v', 'm'}) -) - -// Factory ... -type Factory struct{} - -// New ... -func (f *Factory) New() interface{} { return &VM{} } diff --git a/vms/evm/service.go b/vms/evm/service.go deleted file mode 100644 index 70135cc..0000000 --- a/vms/evm/service.go +++ /dev/null @@ -1,122 +0,0 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package evm - -import ( - "context" - "crypto/rand" - "fmt" - "math/big" - - "github.com/ava-labs/coreth" - - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/common/hexutil" - "github.com/ava-labs/go-ethereum/core/types" - "github.com/ava-labs/go-ethereum/crypto" -) - -const ( - version = "Athereum 1.0" -) - -// test constants -const ( - GenesisTestAddr = "0x751a0b96e1042bee789452ecb20253fba40dbe85" - GenesisTestKey = "0xabd71b35d559563fea757f0f5edbde286fb8c043105b15abb7cd57189306d7d1" -) - -// DebugAPI introduces helper functions for debuging -type DebugAPI struct{ vm *VM } - -// SnowmanAPI introduces snowman specific functionality to the evm -type SnowmanAPI struct{ vm *VM } - -// NetAPI offers network related API methods -type NetAPI struct{ vm *VM } - -// NewNetAPI creates a new net API instance. -func NewNetAPI(vm *VM) *NetAPI { return &NetAPI{vm} } - -// Listening returns an indication if the node is listening for network connections. -func (s *NetAPI) Listening() bool { return true } // always listening - -// PeerCount returns the number of connected peers -func (s *NetAPI) PeerCount() hexutil.Uint { return hexutil.Uint(0) } // TODO: report number of connected peers - -// Version returns the current ethereum protocol version. -func (s *NetAPI) Version() string { return fmt.Sprintf("%d", s.vm.networkID) } - -// Web3API offers helper API methods -type Web3API struct{} - -// ClientVersion returns the version of the vm running -func (s *Web3API) ClientVersion() string { return version } - -// Sha3 returns the bytes returned by hashing [input] with Keccak256 -func (s *Web3API) Sha3(input hexutil.Bytes) hexutil.Bytes { return crypto.Keccak256(input) } - -// GetAcceptedFrontReply defines the reply that will be sent from the -// GetAcceptedFront API call -type GetAcceptedFrontReply struct { - Hash common.Hash `json:"hash"` - Number *big.Int `json:"number"` -} - -// GetAcceptedFront returns the last accepted block's hash and height -func (api *SnowmanAPI) GetAcceptedFront(ctx context.Context) (*GetAcceptedFrontReply, error) { - blk := api.vm.getLastAccepted().ethBlock - return &GetAcceptedFrontReply{ - Hash: blk.Hash(), - Number: blk.Number(), - }, nil -} - -// GetGenesisBalance returns the current funds in the genesis -func (api *DebugAPI) GetGenesisBalance(ctx context.Context) (*hexutil.Big, error) { - lastAccepted := api.vm.getLastAccepted() - api.vm.ctx.Log.Verbo("Currently accepted block front: %s", lastAccepted.ethBlock.Hash().Hex()) - state, err := api.vm.chain.BlockState(lastAccepted.ethBlock) - if err != nil { - return nil, err - } - return (*hexutil.Big)(state.GetBalance(common.HexToAddress(GenesisTestAddr))), nil -} - -// SpendGenesis funds -func (api *DebugAPI) SpendGenesis(ctx context.Context, nonce uint64) error { - api.vm.ctx.Log.Info("Spending the genesis") - - value := big.NewInt(1000000000000) - gasLimit := 21000 - gasPrice := big.NewInt(1000000000) - - genPrivateKey, err := crypto.HexToECDSA(GenesisTestKey[2:]) - if err != nil { - return err - } - bob, err := coreth.NewKey(rand.Reader) - if err != nil { - return err - } - - tx := types.NewTransaction(nonce, bob.Address, value, uint64(gasLimit), gasPrice, nil) - signedTx, err := types.SignTx(tx, types.NewEIP155Signer(api.vm.chainID), genPrivateKey) - if err != nil { - return err - } - - if err := api.vm.issueRemoteTxs([]*types.Transaction{signedTx}); err != nil { - return err - } - - return nil -} - -// IssueBlock to the chain -func (api *DebugAPI) IssueBlock(ctx context.Context) error { - api.vm.ctx.Log.Info("Issuing a new block") - - return api.vm.tryBlockGen() -} diff --git a/vms/evm/static_service.go b/vms/evm/static_service.go deleted file mode 100644 index d3870ca..0000000 --- a/vms/evm/static_service.go +++ /dev/null @@ -1,22 +0,0 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package evm - -import ( - "context" - "encoding/json" - - "github.com/ava-labs/coreth/core" - "github.com/ava-labs/gecko/utils/formatting" -) - -// StaticService defines the static API services exposed by the evm -type StaticService struct{} - -// BuildGenesis returns the UTXOs such that at least one address in [args.Addresses] is -// referenced in the UTXO. -func (*StaticService) BuildGenesis(_ context.Context, args *core.Genesis) (formatting.CB58, error) { - bytes, err := json.Marshal(args) - return formatting.CB58{Bytes: bytes}, err -} diff --git a/vms/evm/static_service_test.go b/vms/evm/static_service_test.go deleted file mode 100644 index c492798..0000000 --- a/vms/evm/static_service_test.go +++ /dev/null @@ -1,64 +0,0 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package evm - -import ( - "math/big" - "testing" - - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/params" - - "github.com/ava-labs/coreth/core" -) - -func TestBuildGenesis(t *testing.T) { - expected := "3wP629bGfSGj9trh1UNBp5qGRGCcma5d8ezLeSmd9hnUJjSMUJesHHoxbZNcVUC9CjH7PEGNA96htNTd1saZCMt1Mf1dZFG7JDhcYNok6RS4TZufejXdxbVVgquohSa7nCCcrXpiVeiRFwzLJAxyQbXzYRhaCRtcDDfCcqfaVdtkFsPbNeQ49pDTbEC5hVkmfopeQ2Zz8tAG5QXKBdbYBCukR3xNHJ4xDxeixmEwPr1odb42yQRYrL7xREKNn2LFoFwAWUjBTsCkf5GPNgY2GvvN9o8wFWXTroW5fp754DhpdxHYxkMTfuE9DGyNWHTyrEbrUHutUdsfitcSHVj5ctFtkN2wGCs3cyv1eRRNvFFMggWTbarjne6AYaeCrJ631qAu3CbrUtrTH5N2E6G2yQKX4sT4Sk3qWPJdsGXuT95iKKcgNn1u5QRHHw9DXXuGPpJjkcKQRGUCuqpXy61iF5RNPEwAwKDa8f2Y25WMmNgWynUuLj8iSAyePj7USPWk54QFUr86ApVzqAdzzdD1qSVScpmudGnGbz9UNXdzHqSot6XLrNTYsgkabiu6TGntFm7qywbCRmtNdBuT9aznGQdUVimjt5QzUz68HXhUxBzTkrz7yXfVGV5JcWxVHQXYS4oc41U5yu83mH3A7WBrZLVq6UyNrvQVbim5nDxeKKbALPxwzVwywjgY5cp39AvzGnY8CX2AtuBNnKmZaAvG8JWAkx3yxjnJrwWhLgpDQYcCvRp2jg1EPBqN8FKJxSPE6eedjDHDJfB57mNzyEtmg22BPnem3eLdiovX8awkhBUHdE7uPrapNSVprnS85u1saW2Kwza3FsS2jAM3LckGW8KdtfPTpHBTRKAUo49zZLuPsyGL5WduedGyAdaM3a2KPoyXuz4UbexTVUWFNypFvvgyoDS8FMxDCNoMMaD7y4yVnoDpSpVFEVZD6EuSGHe9U8Ew57xLPbjhepDx6" - - balance, success := new(big.Int).SetString("33b2e3c9fd0804000000000", 16) - if !success { - t.Fatal("Failed to initialize balance") - } - - args := core.Genesis{ - Config: ¶ms.ChainConfig{ - ChainID: big.NewInt(43110), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: big.NewInt(0), - DAOForkSupport: true, - EIP150Block: big.NewInt(0), - EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - }, - Nonce: 0, - Timestamp: 0, - ExtraData: []byte{}, - GasLimit: 100000000, - Difficulty: big.NewInt(0), - Mixhash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), - Coinbase: common.HexToAddress("0x0000000000000000000000000000000000000000"), - Alloc: core.GenesisAlloc{ - common.HexToAddress("751a0b96e1042bee789452ecb20253fba40dbe85"): core.GenesisAccount{ - Balance: balance, - }, - }, - Number: 0, - GasUsed: 0, - ParentHash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), - } - - ss := StaticService{} - result, err := ss.BuildGenesis(nil, &args) - if err != nil { - t.Fatal(err) - } - - if result.String() != expected { - t.Fatalf("StaticService.BuildGenesis:\nReturned: %s\nExpected: %s", result, expected) - } -} diff --git a/vms/evm/vm.go b/vms/evm/vm.go deleted file mode 100644 index e1e9846..0000000 --- a/vms/evm/vm.go +++ /dev/null @@ -1,498 +0,0 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package evm - -import ( - "crypto/rand" - "encoding/json" - "errors" - "fmt" - "math/big" - "sync" - "sync/atomic" - "time" - - "github.com/ava-labs/coreth" - "github.com/ava-labs/coreth/core" - "github.com/ava-labs/coreth/eth" - "github.com/ava-labs/coreth/node" - - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/core/types" - "github.com/ava-labs/go-ethereum/rlp" - "github.com/ava-labs/go-ethereum/rpc" - - "github.com/ava-labs/gecko/cache" - "github.com/ava-labs/gecko/database" - "github.com/ava-labs/gecko/ids" - "github.com/ava-labs/gecko/snow" - "github.com/ava-labs/gecko/snow/choices" - "github.com/ava-labs/gecko/snow/consensus/snowman" - "github.com/ava-labs/gecko/utils/timer" - - commonEng "github.com/ava-labs/gecko/snow/engine/common" -) - -const ( - lastAcceptedKey = "snowman_lastAccepted" -) - -const ( - minBlockTime = 250 * time.Millisecond - maxBlockTime = 1000 * time.Millisecond - batchSize = 250 -) - -const ( - bdTimerStateMin = iota - bdTimerStateMax - bdTimerStateLong -) - -var ( - errEmptyBlock = errors.New("empty block") - errCreateBlock = errors.New("couldn't create block") - errUnknownBlock = errors.New("unknown block") - errBlockFrequency = errors.New("too frequent block issuance") - errUnsupportedFXs = errors.New("unsupported feature extensions") -) - -func maxDuration(x, y time.Duration) time.Duration { - if x > y { - return x - } - return y -} - -// VM implements the snowman.ChainVM interface -type VM struct { - ctx *snow.Context - - chainID *big.Int - networkID uint64 - chain *coreth.ETHChain - chaindb Database - newBlockChan chan *Block - networkChan chan<- commonEng.Message - newTxPoolHeadChan chan core.NewTxPoolHeadEvent - - txPoolStabilizedHead common.Hash - txPoolStabilizedOk chan struct{} - txPoolStabilizedLock sync.Mutex - - metalock sync.Mutex - blockCache, blockStatusCache cache.LRU - lastAccepted *Block - writingMetadata uint32 - - bdlock sync.Mutex - blockDelayTimer *timer.Timer - bdTimerState int8 - bdGenWaitFlag bool - bdGenFlag bool - - genlock sync.Mutex - txSubmitChan <-chan struct{} -} - -/* - ****************************************************************************** - ********************************* Snowman API ******************************** - ****************************************************************************** - */ - -// Initialize implements the snowman.ChainVM interface -func (vm *VM) Initialize( - ctx *snow.Context, - db database.Database, - b []byte, - toEngine chan<- commonEng.Message, - fxs []*commonEng.Fx, -) error { - if len(fxs) > 0 { - return errUnsupportedFXs - } - - vm.ctx = ctx - vm.chaindb = Database{db} - g := new(core.Genesis) - err := json.Unmarshal(b, g) - if err != nil { - return err - } - - vm.chainID = g.Config.ChainID - - config := eth.DefaultConfig - config.ManualCanonical = true - config.Genesis = g - config.Miner.ManualMining = true - config.Miner.DisableUncle = true - if err := config.SetGCMode("archive"); err != nil { - panic(err) - } - nodecfg := node.Config{NoUSB: true} - chain := coreth.NewETHChain(&config, &nodecfg, nil, vm.chaindb) - vm.chain = chain - vm.networkID = config.NetworkId - chain.SetOnHeaderNew(func(header *types.Header) { - hid := make([]byte, 32) - _, err := rand.Read(hid) - if err != nil { - panic("cannot generate hid") - } - header.Extra = append(header.Extra, hid...) - }) - chain.SetOnSeal(func(block *types.Block) error { - if len(block.Transactions()) == 0 { - // this could happen due to the async logic of geth tx pool - vm.newBlockChan <- nil - return errEmptyBlock - } - return nil - }) - chain.SetOnSealFinish(func(block *types.Block) error { - vm.ctx.Log.Verbo("EVM sealed a block") - - blk := &Block{ - id: ids.NewID(block.Hash()), - ethBlock: block, - vm: vm, - } - vm.newBlockChan <- blk - vm.updateStatus(ids.NewID(block.Hash()), choices.Processing) - vm.txPoolStabilizedLock.Lock() - vm.txPoolStabilizedHead = block.Hash() - vm.txPoolStabilizedLock.Unlock() - return nil - }) - chain.SetOnQueryAcceptedBlock(func() *types.Block { - return vm.getLastAccepted().ethBlock - }) - vm.blockCache = cache.LRU{Size: 2048} - vm.blockStatusCache = cache.LRU{Size: 1024} - vm.newBlockChan = make(chan *Block) - vm.networkChan = toEngine - vm.blockDelayTimer = timer.NewTimer(func() { - vm.bdlock.Lock() - switch vm.bdTimerState { - case bdTimerStateMin: - vm.bdTimerState = bdTimerStateMax - vm.blockDelayTimer.SetTimeoutIn(maxDuration(maxBlockTime-minBlockTime, 0)) - case bdTimerStateMax: - vm.bdTimerState = bdTimerStateLong - } - tryAgain := vm.bdGenWaitFlag - vm.bdlock.Unlock() - if tryAgain { - vm.tryBlockGen() - } - }) - go ctx.Log.RecoverAndPanic(vm.blockDelayTimer.Dispatch) - - vm.bdTimerState = bdTimerStateLong - vm.bdGenWaitFlag = true - vm.newTxPoolHeadChan = make(chan core.NewTxPoolHeadEvent, 1) - vm.txPoolStabilizedOk = make(chan struct{}, 1) - chain.GetTxPool().SubscribeNewHeadEvent(vm.newTxPoolHeadChan) - // TODO: shutdown this go routine - go ctx.Log.RecoverAndPanic(func() { - for { - select { - case h := <-vm.newTxPoolHeadChan: - vm.txPoolStabilizedLock.Lock() - if vm.txPoolStabilizedHead == h.Block.Hash() { - vm.txPoolStabilizedOk <- struct{}{} - vm.txPoolStabilizedHead = common.Hash{} - } - vm.txPoolStabilizedLock.Unlock() - } - } - }) - chain.Start() - - var lastAccepted *types.Block - if b, err := vm.chaindb.Get([]byte(lastAcceptedKey)); err == nil { - var hash common.Hash - if err = rlp.DecodeBytes(b, &hash); err == nil { - if block := chain.GetBlockByHash(hash); block == nil { - vm.ctx.Log.Debug("lastAccepted block not found in chaindb") - } else { - lastAccepted = block - } - } - } - if lastAccepted == nil { - vm.ctx.Log.Debug("lastAccepted is unavailable, setting to the genesis block") - lastAccepted = chain.GetGenesisBlock() - } - vm.lastAccepted = &Block{ - id: ids.NewID(lastAccepted.Hash()), - ethBlock: lastAccepted, - vm: vm, - } - vm.ctx.Log.Info(fmt.Sprintf("lastAccepted = %s", vm.lastAccepted.ethBlock.Hash().Hex())) - - // TODO: shutdown this go routine - go vm.ctx.Log.RecoverAndPanic(func() { - vm.txSubmitChan = vm.chain.GetTxSubmitCh() - for { - select { - case <-vm.txSubmitChan: - vm.ctx.Log.Verbo("New tx detected, trying to generate a block") - vm.tryBlockGen() - case <-time.After(5 * time.Second): - vm.tryBlockGen() - } - } - }) - - return nil -} - -// Shutdown implements the snowman.ChainVM interface -func (vm *VM) Shutdown() { - vm.writeBackMetadata() - vm.chain.Stop() -} - -// BuildBlock implements the snowman.ChainVM interface -func (vm *VM) BuildBlock() (snowman.Block, error) { - vm.chain.GenBlock() - block := <-vm.newBlockChan - if block == nil { - return nil, errCreateBlock - } - // reset the min block time timer - vm.bdlock.Lock() - vm.bdTimerState = bdTimerStateMin - vm.bdGenWaitFlag = false - vm.bdGenFlag = false - vm.blockDelayTimer.SetTimeoutIn(minBlockTime) - vm.bdlock.Unlock() - - vm.ctx.Log.Debug("built block 0x%x", block.ID().Bytes()) - // make sure Tx Pool is updated - <-vm.txPoolStabilizedOk - return block, nil -} - -// ParseBlock implements the snowman.ChainVM interface -func (vm *VM) ParseBlock(b []byte) (snowman.Block, error) { - vm.metalock.Lock() - defer vm.metalock.Unlock() - - ethBlock := new(types.Block) - if err := rlp.DecodeBytes(b, ethBlock); err != nil { - return nil, err - } - block := &Block{ - id: ids.NewID(ethBlock.Hash()), - ethBlock: ethBlock, - vm: vm, - } - vm.blockCache.Put(block.ID(), block) - return block, nil -} - -// GetBlock implements the snowman.ChainVM interface -func (vm *VM) GetBlock(id ids.ID) (snowman.Block, error) { - vm.metalock.Lock() - defer vm.metalock.Unlock() - - block := vm.getBlock(id) - if block == nil { - return nil, errUnknownBlock - } - return block, nil -} - -// SetPreference sets what the current tail of the chain is -func (vm *VM) SetPreference(blkID ids.ID) { - err := vm.chain.SetTail(blkID.Key()) - vm.ctx.Log.AssertNoError(err) -} - -// LastAccepted returns the ID of the block that was last accepted -func (vm *VM) LastAccepted() ids.ID { - vm.metalock.Lock() - defer vm.metalock.Unlock() - - return vm.lastAccepted.ID() -} - -// CreateHandlers makes new http handlers that can handle API calls -func (vm *VM) CreateHandlers() map[string]*commonEng.HTTPHandler { - handler := vm.chain.NewRPCHandler() - vm.chain.AttachEthService(handler, []string{"eth", "personal", "txpool"}) - handler.RegisterName("net", &NetAPI{vm}) - handler.RegisterName("snowman", &SnowmanAPI{vm}) - handler.RegisterName("web3", &Web3API{}) - handler.RegisterName("debug", &DebugAPI{vm}) - - return map[string]*commonEng.HTTPHandler{ - "/rpc": &commonEng.HTTPHandler{LockOptions: commonEng.NoLock, Handler: handler}, - "/ws": &commonEng.HTTPHandler{LockOptions: commonEng.NoLock, Handler: handler.WebsocketHandler([]string{"*"})}, - } -} - -// CreateStaticHandlers makes new http handlers that can handle API calls -func (vm *VM) CreateStaticHandlers() map[string]*commonEng.HTTPHandler { - handler := rpc.NewServer() - handler.RegisterName("static", &StaticService{}) - return map[string]*commonEng.HTTPHandler{ - "/rpc": &commonEng.HTTPHandler{LockOptions: commonEng.NoLock, Handler: handler}, - "/ws": &commonEng.HTTPHandler{LockOptions: commonEng.NoLock, Handler: handler.WebsocketHandler([]string{"*"})}, - } -} - -/* - ****************************************************************************** - *********************************** Helpers ********************************** - ****************************************************************************** - */ - -func (vm *VM) updateStatus(blockID ids.ID, status choices.Status) { - vm.metalock.Lock() - defer vm.metalock.Unlock() - - if status == choices.Accepted { - vm.lastAccepted = vm.getBlock(blockID) - // TODO: improve this naive implementation - if atomic.SwapUint32(&vm.writingMetadata, 1) == 0 { - go vm.ctx.Log.RecoverAndPanic(vm.writeBackMetadata) - } - } - vm.blockStatusCache.Put(blockID, status) -} - -func (vm *VM) getCachedBlock(blockID ids.ID) *types.Block { - return vm.chain.GetBlockByHash(blockID.Key()) -} - -func (vm *VM) tryBlockGen() error { - vm.bdlock.Lock() - defer vm.bdlock.Unlock() - if vm.bdGenFlag { - // skip if one call already generates a block in this round - return nil - } - vm.bdGenWaitFlag = true - - vm.genlock.Lock() - defer vm.genlock.Unlock() - // get pending size - size, err := vm.chain.PendingSize() - if err != nil { - return err - } - if size == 0 { - return nil - } - - switch vm.bdTimerState { - case bdTimerStateMin: - return nil - case bdTimerStateMax: - if size < batchSize { - return nil - } - case bdTimerStateLong: - // timeout; go ahead and generate a new block anyway - } - select { - case vm.networkChan <- commonEng.PendingTxs: - // successfully push out the notification; this round ends - vm.bdGenFlag = true - default: - return errBlockFrequency - } - return nil -} - -func (vm *VM) getCachedStatus(blockID ids.ID) choices.Status { - vm.metalock.Lock() - defer vm.metalock.Unlock() - status := choices.Processing - - if statusIntf, ok := vm.blockStatusCache.Get(blockID); ok { - status = statusIntf.(choices.Status) - } else { - blk := vm.chain.GetBlockByHash(blockID.Key()) - if blk == nil { - return choices.Unknown - } - acceptedBlk := vm.lastAccepted.ethBlock - - // TODO: There must be a better way of doing this. - // Traverse up the chain from the lower block until the indices match - highBlock := blk - lowBlock := acceptedBlk - if highBlock.Number().Cmp(lowBlock.Number()) < 0 { - highBlock, lowBlock = lowBlock, highBlock - } - for highBlock.Number().Cmp(lowBlock.Number()) > 0 { - highBlock = vm.chain.GetBlockByHash(highBlock.ParentHash()) - } - - if highBlock.Hash() == lowBlock.Hash() { // on the same branch - if blk.Number().Cmp(acceptedBlk.Number()) <= 0 { - status = choices.Accepted - } - } else { // on different branches - status = choices.Rejected - } - } - - vm.blockStatusCache.Put(blockID, status) - return status -} - -func (vm *VM) getBlock(id ids.ID) *Block { - if blockIntf, ok := vm.blockCache.Get(id); ok { - return blockIntf.(*Block) - } - ethBlock := vm.getCachedBlock(id) - if ethBlock == nil { - return nil - } - block := &Block{ - id: ids.NewID(ethBlock.Hash()), - ethBlock: ethBlock, - vm: vm, - } - vm.blockCache.Put(id, block) - return block -} - -func (vm *VM) issueRemoteTxs(txs []*types.Transaction) error { - errs := vm.chain.AddRemoteTxs(txs) - for _, err := range errs { - if err != nil { - return err - } - } - return vm.tryBlockGen() -} - -func (vm *VM) writeBackMetadata() { - vm.metalock.Lock() - defer vm.metalock.Unlock() - - b, err := rlp.EncodeToBytes(vm.lastAccepted.ethBlock.Hash()) - if err != nil { - vm.ctx.Log.Error("snowman-eth: error while writing back metadata") - return - } - vm.ctx.Log.Debug("writing back metadata") - vm.chaindb.Put([]byte(lastAcceptedKey), b) - atomic.StoreUint32(&vm.writingMetadata, 0) -} - -func (vm *VM) getLastAccepted() *Block { - vm.metalock.Lock() - defer vm.metalock.Unlock() - - return vm.lastAccepted -} diff --git a/vms/evm/vm_genesis_parse_test.go b/vms/evm/vm_genesis_parse_test.go deleted file mode 100644 index 9a113fb..0000000 --- a/vms/evm/vm_genesis_parse_test.go +++ /dev/null @@ -1,32 +0,0 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package evm - -import ( - "encoding/json" - "testing" - - "github.com/ava-labs/coreth/core" -) - -func TestParseGenesis(t *testing.T) { - genesis := []byte(`{"config":{"chainId":43110,"homesteadBlock":0,"daoForkBlock":0,"daoForkSupport":true,"eip150Block":0,"eip150Hash":"0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0","eip155Block":0,"eip158Block":0,"byzantiumBlock":0,"constantinopleBlock":0,"petersburgBlock":0},"nonce":"0x0","timestamp":"0x0","extraData":"0x00","gasLimit":"0x5f5e100","difficulty":"0x0","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","coinbase":"0x0000000000000000000000000000000000000000","alloc":{"751a0b96e1042bee789452ecb20253fba40dbe85":{"balance":"0x33b2e3c9fd0804000000000"}},"number":"0x0","gasUsed":"0x0","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000"}`) - - genesisBlock := new(core.Genesis) - err := json.Unmarshal(genesis, genesisBlock) - if err != nil { - t.Fatal(err) - } - - marshalledBytes, err := json.Marshal(genesisBlock) - if err != nil { - t.Fatal(err) - } - - secondGenesisBlock := new(core.Genesis) - err = json.Unmarshal(marshalledBytes, secondGenesisBlock) - if err != nil { - t.Fatal(err) - } -} diff --git a/vms/manager.go b/vms/manager.go index 1509d49..9f8cf3b 100644 --- a/vms/manager.go +++ b/vms/manager.go @@ -16,7 +16,7 @@ import ( // A VMFactory creates new instances of a VM type VMFactory interface { - New() interface{} + New() (interface{}, error) } // Manager is a VM manager. @@ -110,10 +110,17 @@ func (m *manager) addStaticAPIEndpoints(vmID ids.ID) { vmFactory, err := m.GetVMFactory(vmID) m.log.AssertNoError(err) m.log.Debug("adding static API for VM with ID %s", vmID) - vm := vmFactory.New() + vm, err := vmFactory.New() + if err != nil { + return + } staticVM, ok := vm.(common.StaticVM) if !ok { + staticVM, ok := vm.(common.VM) + if ok { + staticVM.Shutdown() + } return } diff --git a/vms/nftfx/factory.go b/vms/nftfx/factory.go index 5a3b0c2..fc28262 100644 --- a/vms/nftfx/factory.go +++ b/vms/nftfx/factory.go @@ -13,4 +13,4 @@ var ( type Factory struct{} // New ... -func (f *Factory) New() interface{} { return &Fx{} } +func (f *Factory) New() (interface{}, error) { return &Fx{}, nil } diff --git a/vms/nftfx/factory_test.go b/vms/nftfx/factory_test.go index 0f533c9..7144129 100644 --- a/vms/nftfx/factory_test.go +++ b/vms/nftfx/factory_test.go @@ -6,7 +6,9 @@ import ( func TestFactory(t *testing.T) { factory := Factory{} - if fx := factory.New(); fx == nil { + if fx, err := factory.New(); err != nil { + t.Fatal(err) + } else if fx == nil { t.Fatalf("Factory.New returned nil") } } diff --git a/vms/platformvm/factory.go b/vms/platformvm/factory.go index 7cdd916..c55c070 100644 --- a/vms/platformvm/factory.go +++ b/vms/platformvm/factory.go @@ -24,12 +24,12 @@ type Factory struct { } // New returns a new instance of the Platform Chain -func (f *Factory) New() interface{} { +func (f *Factory) New() (interface{}, error) { return &VM{ chainManager: f.ChainManager, validators: f.Validators, stakingEnabled: f.StakingEnabled, ava: f.AVA, avm: f.AVM, - } + }, nil } diff --git a/vms/platformvm/vm.go b/vms/platformvm/vm.go index 10fc512..3e4bf78 100644 --- a/vms/platformvm/vm.go +++ b/vms/platformvm/vm.go @@ -382,6 +382,10 @@ func (vm *VM) createChain(tx *CreateChainTx) { // Shutdown this blockchain func (vm *VM) Shutdown() { + if vm.timer == nil { + return + } + vm.timer.Stop() if err := vm.DB.Close(); err != nil { vm.Ctx.Log.Error("Closing the database failed with %s", err) diff --git a/vms/propertyfx/factory.go b/vms/propertyfx/factory.go index 6cb6fba..67ebb5a 100644 --- a/vms/propertyfx/factory.go +++ b/vms/propertyfx/factory.go @@ -13,4 +13,4 @@ var ( type Factory struct{} // New ... -func (f *Factory) New() interface{} { return &Fx{} } +func (f *Factory) New() (interface{}, error) { return &Fx{}, nil } diff --git a/vms/propertyfx/factory_test.go b/vms/propertyfx/factory_test.go index a22fdd2..d49d27c 100644 --- a/vms/propertyfx/factory_test.go +++ b/vms/propertyfx/factory_test.go @@ -6,7 +6,9 @@ import ( func TestFactory(t *testing.T) { factory := Factory{} - if fx := factory.New(); fx == nil { + if fx, err := factory.New(); err != nil { + t.Fatal(err) + } else if fx == nil { t.Fatalf("Factory.New returned nil") } } diff --git a/vms/rpcchainvm/factory.go b/vms/rpcchainvm/factory.go new file mode 100644 index 0000000..78e1ead --- /dev/null +++ b/vms/rpcchainvm/factory.go @@ -0,0 +1,54 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package rpcchainvm + +import ( + "errors" + "os/exec" + + "github.com/hashicorp/go-plugin" +) + +var ( + errWrongVM = errors.New("wrong vm type") +) + +// Factory ... +type Factory struct { + Path string +} + +// New ... +func (f *Factory) New() (interface{}, error) { + client := plugin.NewClient(&plugin.ClientConfig{ + HandshakeConfig: Handshake, + Plugins: PluginMap, + Cmd: exec.Command("sh", "-c", f.Path), + AllowedProtocols: []plugin.Protocol{ + plugin.ProtocolNetRPC, + plugin.ProtocolGRPC, + }, + }) + + rpcClient, err := client.Client() + if err != nil { + client.Kill() + return nil, err + } + + raw, err := rpcClient.Dispense("vm") + if err != nil { + client.Kill() + return nil, err + } + + vm, ok := raw.(*VMClient) + if !ok { + client.Kill() + return nil, errWrongVM + } + + vm.SetProcess(client) + return vm, nil +} diff --git a/vms/rpcchainvm/ghttp/http_client.go b/vms/rpcchainvm/ghttp/http_client.go new file mode 100644 index 0000000..e06ef2c --- /dev/null +++ b/vms/rpcchainvm/ghttp/http_client.go @@ -0,0 +1,64 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package ghttp + +import ( + "io/ioutil" + "net/http" + + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/proto" +) + +// Client is an implementation of a messenger channel that talks over RPC. +type Client struct{ client proto.HTTPClient } + +// NewClient returns a database instance connected to a remote database instance +func NewClient(client proto.HTTPClient) *Client { + return &Client{client: client} +} + +// Handle ... +func (c *Client) ServeHTTP(w http.ResponseWriter, r *http.Request) { + // get the headers + inboundHeaders := make([]*proto.Header, len(r.Header))[:0] + for key, values := range r.Header { + inboundHeaders = append(inboundHeaders, &proto.Header{ + Key: key, + Values: values, + }) + } + + // get the body + body, err := ioutil.ReadAll(r.Body) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + // execute the call + resp, err := c.client.Handle(r.Context(), &proto.HTTPRequest{ + Url: r.RequestURI, + Method: r.Method, + Headers: inboundHeaders, + Body: body, + }) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + // return the code + w.WriteHeader(int(resp.Code)) + + // return the headers + outboundHeaders := w.Header() + for _, header := range resp.Headers { + outboundHeaders[header.Key] = header.Values + } + + // return the body + if _, err := w.Write(resp.Body); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } +} diff --git a/vms/rpcchainvm/ghttp/http_server.go b/vms/rpcchainvm/ghttp/http_server.go new file mode 100644 index 0000000..0ee8eb0 --- /dev/null +++ b/vms/rpcchainvm/ghttp/http_server.go @@ -0,0 +1,62 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package ghttp + +import ( + "bytes" + "context" + "io/ioutil" + "net/http" + "net/http/httptest" + + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/proto" +) + +// Server is a http.Handler that is managed over RPC. +type Server struct{ handler http.Handler } + +// NewServer returns a http.Handler instance manage remotely +func NewServer(handler http.Handler) *Server { + return &Server{handler: handler} +} + +// Handle ... +func (s Server) Handle(ctx context.Context, req *proto.HTTPRequest) (*proto.HTTPResponse, error) { + // create the request with the current context + r, err := http.NewRequestWithContext( + ctx, + req.Method, + req.Url, + ioutil.NopCloser(bytes.NewReader(req.Body)), + ) + if err != nil { + return nil, err + } + + // populate the headers + for _, header := range req.Headers { + r.Header[header.Key] = header.Values + } + + // send the request to the recorder + recorder := httptest.NewRecorder() + s.handler.ServeHTTP(recorder, r) + + // get the returned headers + returnedHeaders := recorder.Header() + headers := make([]*proto.Header, len(returnedHeaders))[:0] + for key, values := range returnedHeaders { + headers = append(headers, &proto.Header{ + Key: key, + Values: values, + }) + } + + // return the response + return &proto.HTTPResponse{ + Code: int32(recorder.Code), + Headers: headers, + Body: recorder.Body.Bytes(), + }, nil +} diff --git a/vms/rpcchainvm/ghttp/http_test.go b/vms/rpcchainvm/ghttp/http_test.go new file mode 100644 index 0000000..0c60f27 --- /dev/null +++ b/vms/rpcchainvm/ghttp/http_test.go @@ -0,0 +1,96 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package ghttp + +import ( + "bytes" + "log" + "net" + "net/http" + "net/http/httptest" + "testing" + + "golang.org/x/net/context" + + "google.golang.org/grpc" + "google.golang.org/grpc/test/bufconn" + + "github.com/gorilla/rpc/v2" + "github.com/gorilla/rpc/v2/json2" + + "github.com/ava-labs/gecko/utils/json" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/proto" +) + +const ( + bufSize = 1 << 20 +) + +type service struct{} + +type Args struct{} + +type Reply struct { + Called bool +} + +func (s *service) Call(r *http.Request, args *Args, reply *Reply) error { + reply.Called = true + return nil +} + +func TestRPC(t *testing.T) { + rpcServer := rpc.NewServer() + codec := json.NewCodec() + rpcServer.RegisterCodec(codec, "application/json") + rpcServer.RegisterCodec(codec, "application/json;charset=UTF-8") + rpcServer.RegisterService(&service{}, "service") + + listener := bufconn.Listen(bufSize) + server := grpc.NewServer() + proto.RegisterHTTPServer(server, NewServer(rpcServer)) + go func() { + if err := server.Serve(listener); err != nil { + log.Fatal(err) + } + }() + + dialer := grpc.WithContextDialer( + func(context.Context, string) (net.Conn, error) { + return listener.Dial() + }) + + ctx := context.Background() + conn, err := grpc.DialContext(ctx, "", dialer, grpc.WithInsecure()) + if err != nil { + t.Fatal(err) + } + defer conn.Close() + + rpcClient := NewClient(proto.NewHTTPClient(conn)) + + req := &Args{} + buf, err := json2.EncodeClientRequest("service.call", req) + if err != nil { + t.Fatal(err) + } + body := bytes.NewBuffer(buf) + r, err := http.NewRequest("POST", "http://localhost:8080/", body) + if err != nil { + t.Fatal(err) + } + r.Header.Set("Content-Type", "application/json") + + w := httptest.NewRecorder() + rpcClient.ServeHTTP(w, r) + + res := &Reply{} + if err := json2.DecodeClientResponse(w.Body, res); err != nil { + t.Fatal(err) + } + + if !res.Called { + t.Fatalf("Should have called the function") + } +} diff --git a/vms/rpcchainvm/ghttp/proto/http.pb.go b/vms/rpcchainvm/ghttp/proto/http.pb.go new file mode 100644 index 0000000..e654dde --- /dev/null +++ b/vms/rpcchainvm/ghttp/proto/http.pb.go @@ -0,0 +1,297 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: http.proto + +package proto + +import ( + context "context" + fmt "fmt" + proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type Header struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Values []string `protobuf:"bytes,2,rep,name=values,proto3" json:"values,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Header) Reset() { *m = Header{} } +func (m *Header) String() string { return proto.CompactTextString(m) } +func (*Header) ProtoMessage() {} +func (*Header) Descriptor() ([]byte, []int) { + return fileDescriptor_11b04836674e6f94, []int{0} +} + +func (m *Header) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Header.Unmarshal(m, b) +} +func (m *Header) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Header.Marshal(b, m, deterministic) +} +func (m *Header) XXX_Merge(src proto.Message) { + xxx_messageInfo_Header.Merge(m, src) +} +func (m *Header) XXX_Size() int { + return xxx_messageInfo_Header.Size(m) +} +func (m *Header) XXX_DiscardUnknown() { + xxx_messageInfo_Header.DiscardUnknown(m) +} + +var xxx_messageInfo_Header proto.InternalMessageInfo + +func (m *Header) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *Header) GetValues() []string { + if m != nil { + return m.Values + } + return nil +} + +type HTTPRequest struct { + Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"` + Method string `protobuf:"bytes,2,opt,name=method,proto3" json:"method,omitempty"` + Headers []*Header `protobuf:"bytes,3,rep,name=headers,proto3" json:"headers,omitempty"` + Body []byte `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *HTTPRequest) Reset() { *m = HTTPRequest{} } +func (m *HTTPRequest) String() string { return proto.CompactTextString(m) } +func (*HTTPRequest) ProtoMessage() {} +func (*HTTPRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_11b04836674e6f94, []int{1} +} + +func (m *HTTPRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_HTTPRequest.Unmarshal(m, b) +} +func (m *HTTPRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_HTTPRequest.Marshal(b, m, deterministic) +} +func (m *HTTPRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_HTTPRequest.Merge(m, src) +} +func (m *HTTPRequest) XXX_Size() int { + return xxx_messageInfo_HTTPRequest.Size(m) +} +func (m *HTTPRequest) XXX_DiscardUnknown() { + xxx_messageInfo_HTTPRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_HTTPRequest proto.InternalMessageInfo + +func (m *HTTPRequest) GetUrl() string { + if m != nil { + return m.Url + } + return "" +} + +func (m *HTTPRequest) GetMethod() string { + if m != nil { + return m.Method + } + return "" +} + +func (m *HTTPRequest) GetHeaders() []*Header { + if m != nil { + return m.Headers + } + return nil +} + +func (m *HTTPRequest) GetBody() []byte { + if m != nil { + return m.Body + } + return nil +} + +type HTTPResponse struct { + Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` + Headers []*Header `protobuf:"bytes,2,rep,name=headers,proto3" json:"headers,omitempty"` + Body []byte `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *HTTPResponse) Reset() { *m = HTTPResponse{} } +func (m *HTTPResponse) String() string { return proto.CompactTextString(m) } +func (*HTTPResponse) ProtoMessage() {} +func (*HTTPResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_11b04836674e6f94, []int{2} +} + +func (m *HTTPResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_HTTPResponse.Unmarshal(m, b) +} +func (m *HTTPResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_HTTPResponse.Marshal(b, m, deterministic) +} +func (m *HTTPResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_HTTPResponse.Merge(m, src) +} +func (m *HTTPResponse) XXX_Size() int { + return xxx_messageInfo_HTTPResponse.Size(m) +} +func (m *HTTPResponse) XXX_DiscardUnknown() { + xxx_messageInfo_HTTPResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_HTTPResponse proto.InternalMessageInfo + +func (m *HTTPResponse) GetCode() int32 { + if m != nil { + return m.Code + } + return 0 +} + +func (m *HTTPResponse) GetHeaders() []*Header { + if m != nil { + return m.Headers + } + return nil +} + +func (m *HTTPResponse) GetBody() []byte { + if m != nil { + return m.Body + } + return nil +} + +func init() { + proto.RegisterType((*Header)(nil), "proto.Header") + proto.RegisterType((*HTTPRequest)(nil), "proto.HTTPRequest") + proto.RegisterType((*HTTPResponse)(nil), "proto.HTTPResponse") +} + +func init() { proto.RegisterFile("http.proto", fileDescriptor_11b04836674e6f94) } + +var fileDescriptor_11b04836674e6f94 = []byte{ + // 225 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x8f, 0x4f, 0x4b, 0x03, 0x31, + 0x14, 0xc4, 0xd9, 0xcd, 0x76, 0xa5, 0xaf, 0x15, 0xe4, 0x09, 0x12, 0x3c, 0x85, 0xbd, 0x98, 0x53, + 0xc1, 0xf5, 0xe4, 0x37, 0xd8, 0xa3, 0x84, 0xde, 0x65, 0x6b, 0x1e, 0x2c, 0x18, 0x9b, 0x35, 0x7f, + 0x84, 0x7e, 0x7b, 0x49, 0xd2, 0xa5, 0x7a, 0xeb, 0x29, 0x33, 0x93, 0x0c, 0xbf, 0x09, 0xc0, 0x14, + 0xc2, 0xbc, 0x9b, 0x9d, 0x0d, 0x16, 0x57, 0xf9, 0xe8, 0x7a, 0x68, 0x07, 0x1a, 0x35, 0x39, 0xbc, + 0x03, 0xf6, 0x49, 0x27, 0x5e, 0x89, 0x4a, 0xae, 0x55, 0x92, 0xf8, 0x00, 0xed, 0xcf, 0x68, 0x22, + 0x79, 0x5e, 0x0b, 0x26, 0xd7, 0xea, 0xec, 0xba, 0x00, 0x9b, 0x61, 0xbf, 0x7f, 0x53, 0xf4, 0x1d, + 0xc9, 0x87, 0x54, 0x8c, 0xce, 0x2c, 0xc5, 0xe8, 0x4c, 0x2a, 0x7e, 0x51, 0x98, 0xac, 0xe6, 0x75, + 0x0e, 0xcf, 0x0e, 0x9f, 0xe0, 0x66, 0xca, 0x30, 0xcf, 0x99, 0x60, 0x72, 0xd3, 0xdf, 0x96, 0x31, + 0xbb, 0x32, 0x41, 0x2d, 0xb7, 0x88, 0xd0, 0x1c, 0xac, 0x3e, 0xf1, 0x46, 0x54, 0x72, 0xab, 0xb2, + 0xee, 0xde, 0x61, 0x5b, 0xa8, 0x7e, 0xb6, 0x47, 0x4f, 0xe9, 0xcd, 0x87, 0xd5, 0x94, 0xb9, 0x2b, + 0x95, 0xf5, 0x5f, 0x40, 0x7d, 0x15, 0x80, 0x5d, 0x00, 0xfd, 0x2b, 0x34, 0x09, 0x80, 0xcf, 0xd0, + 0x0e, 0xe3, 0x51, 0x1b, 0x42, 0x5c, 0xda, 0x97, 0xdf, 0x3e, 0xde, 0xff, 0xcb, 0xca, 0x96, 0x43, + 0x9b, 0xb3, 0x97, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xbf, 0x5a, 0x2a, 0xb5, 0x61, 0x01, 0x00, + 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConnInterface + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion6 + +// HTTPClient is the client API for HTTP service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type HTTPClient interface { + Handle(ctx context.Context, in *HTTPRequest, opts ...grpc.CallOption) (*HTTPResponse, error) +} + +type hTTPClient struct { + cc grpc.ClientConnInterface +} + +func NewHTTPClient(cc grpc.ClientConnInterface) HTTPClient { + return &hTTPClient{cc} +} + +func (c *hTTPClient) Handle(ctx context.Context, in *HTTPRequest, opts ...grpc.CallOption) (*HTTPResponse, error) { + out := new(HTTPResponse) + err := c.cc.Invoke(ctx, "/proto.HTTP/Handle", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// HTTPServer is the server API for HTTP service. +type HTTPServer interface { + Handle(context.Context, *HTTPRequest) (*HTTPResponse, error) +} + +// UnimplementedHTTPServer can be embedded to have forward compatible implementations. +type UnimplementedHTTPServer struct { +} + +func (*UnimplementedHTTPServer) Handle(ctx context.Context, req *HTTPRequest) (*HTTPResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Handle not implemented") +} + +func RegisterHTTPServer(s *grpc.Server, srv HTTPServer) { + s.RegisterService(&_HTTP_serviceDesc, srv) +} + +func _HTTP_Handle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(HTTPRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(HTTPServer).Handle(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.HTTP/Handle", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(HTTPServer).Handle(ctx, req.(*HTTPRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _HTTP_serviceDesc = grpc.ServiceDesc{ + ServiceName: "proto.HTTP", + HandlerType: (*HTTPServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Handle", + Handler: _HTTP_Handle_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "http.proto", +} diff --git a/vms/rpcchainvm/ghttp/proto/http.proto b/vms/rpcchainvm/ghttp/proto/http.proto new file mode 100644 index 0000000..ec23597 --- /dev/null +++ b/vms/rpcchainvm/ghttp/proto/http.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; +package proto; + +message Header { + string key = 1; + repeated string values = 2; +} + +message HTTPRequest { + string url = 1; + string method = 2; + repeated Header headers = 3; + bytes body = 4; +} + +message HTTPResponse { + int32 code = 1; + repeated Header headers = 2; + bytes body = 3; +} + +service HTTP { + rpc Handle(HTTPRequest) returns (HTTPResponse); +} \ No newline at end of file diff --git a/vms/rpcchainvm/messenger/messenger_client.go b/vms/rpcchainvm/messenger/messenger_client.go new file mode 100644 index 0000000..f8f8033 --- /dev/null +++ b/vms/rpcchainvm/messenger/messenger_client.go @@ -0,0 +1,27 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package messenger + +import ( + "context" + + "github.com/ava-labs/gecko/snow/engine/common" + "github.com/ava-labs/gecko/vms/rpcchainvm/messenger/proto" +) + +// Client is an implementation of a messenger channel that talks over RPC. +type Client struct{ client proto.MessengerClient } + +// NewClient returns a database instance connected to a remote database instance +func NewClient(client proto.MessengerClient) *Client { + return &Client{client: client} +} + +// Notify ... +func (c *Client) Notify(msg common.Message) error { + _, err := c.client.Notify(context.Background(), &proto.NotifyRequest{ + Message: uint32(msg), + }) + return err +} diff --git a/vms/rpcchainvm/messenger/messenger_server.go b/vms/rpcchainvm/messenger/messenger_server.go new file mode 100644 index 0000000..a051d7b --- /dev/null +++ b/vms/rpcchainvm/messenger/messenger_server.go @@ -0,0 +1,37 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package messenger + +import ( + "context" + "errors" + + "github.com/ava-labs/gecko/snow/engine/common" + "github.com/ava-labs/gecko/vms/rpcchainvm/messenger/proto" +) + +var ( + errFullQueue = errors.New("full message queue") +) + +// Server is a messenger that is managed over RPC. +type Server struct { + messenger chan<- common.Message +} + +// NewServer returns a vm instance connected to a remote vm instance +func NewServer(messenger chan<- common.Message) *Server { + return &Server{messenger: messenger} +} + +// Notify ... +func (s *Server) Notify(_ context.Context, req *proto.NotifyRequest) (*proto.NotifyResponse, error) { + msg := common.Message(req.Message) + select { + case s.messenger <- msg: + return &proto.NotifyResponse{}, nil + default: + return nil, errFullQueue + } +} diff --git a/vms/rpcchainvm/messenger/proto/messenger.pb.go b/vms/rpcchainvm/messenger/proto/messenger.pb.go new file mode 100644 index 0000000..35dd59c --- /dev/null +++ b/vms/rpcchainvm/messenger/proto/messenger.pb.go @@ -0,0 +1,194 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: messenger.proto + +package proto + +import ( + context "context" + fmt "fmt" + proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type NotifyRequest struct { + Message uint32 `protobuf:"varint,1,opt,name=message,proto3" json:"message,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *NotifyRequest) Reset() { *m = NotifyRequest{} } +func (m *NotifyRequest) String() string { return proto.CompactTextString(m) } +func (*NotifyRequest) ProtoMessage() {} +func (*NotifyRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_b99aba0cbf4e4b91, []int{0} +} + +func (m *NotifyRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_NotifyRequest.Unmarshal(m, b) +} +func (m *NotifyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_NotifyRequest.Marshal(b, m, deterministic) +} +func (m *NotifyRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_NotifyRequest.Merge(m, src) +} +func (m *NotifyRequest) XXX_Size() int { + return xxx_messageInfo_NotifyRequest.Size(m) +} +func (m *NotifyRequest) XXX_DiscardUnknown() { + xxx_messageInfo_NotifyRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_NotifyRequest proto.InternalMessageInfo + +func (m *NotifyRequest) GetMessage() uint32 { + if m != nil { + return m.Message + } + return 0 +} + +type NotifyResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *NotifyResponse) Reset() { *m = NotifyResponse{} } +func (m *NotifyResponse) String() string { return proto.CompactTextString(m) } +func (*NotifyResponse) ProtoMessage() {} +func (*NotifyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_b99aba0cbf4e4b91, []int{1} +} + +func (m *NotifyResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_NotifyResponse.Unmarshal(m, b) +} +func (m *NotifyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_NotifyResponse.Marshal(b, m, deterministic) +} +func (m *NotifyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_NotifyResponse.Merge(m, src) +} +func (m *NotifyResponse) XXX_Size() int { + return xxx_messageInfo_NotifyResponse.Size(m) +} +func (m *NotifyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_NotifyResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_NotifyResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*NotifyRequest)(nil), "proto.NotifyRequest") + proto.RegisterType((*NotifyResponse)(nil), "proto.NotifyResponse") +} + +func init() { proto.RegisterFile("messenger.proto", fileDescriptor_b99aba0cbf4e4b91) } + +var fileDescriptor_b99aba0cbf4e4b91 = []byte{ + // 123 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xcf, 0x4d, 0x2d, 0x2e, + 0x4e, 0xcd, 0x4b, 0x4f, 0x2d, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, 0x4a, + 0x9a, 0x5c, 0xbc, 0x7e, 0xf9, 0x25, 0x99, 0x69, 0x95, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, + 0x42, 0x12, 0x5c, 0xec, 0x20, 0xa5, 0x89, 0xe9, 0xa9, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0xbc, 0x41, + 0x30, 0xae, 0x92, 0x00, 0x17, 0x1f, 0x4c, 0x69, 0x71, 0x41, 0x7e, 0x5e, 0x71, 0xaa, 0x91, 0x13, + 0x17, 0xa7, 0x2f, 0xcc, 0x58, 0x21, 0x53, 0x2e, 0x36, 0x88, 0xb4, 0x90, 0x08, 0xc4, 0x0a, 0x3d, + 0x14, 0x83, 0xa5, 0x44, 0xd1, 0x44, 0x21, 0x66, 0x24, 0xb1, 0x81, 0x45, 0x8d, 0x01, 0x01, 0x00, + 0x00, 0xff, 0xff, 0x39, 0x03, 0x19, 0x97, 0xa1, 0x00, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConnInterface + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion6 + +// MessengerClient is the client API for Messenger service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MessengerClient interface { + Notify(ctx context.Context, in *NotifyRequest, opts ...grpc.CallOption) (*NotifyResponse, error) +} + +type messengerClient struct { + cc grpc.ClientConnInterface +} + +func NewMessengerClient(cc grpc.ClientConnInterface) MessengerClient { + return &messengerClient{cc} +} + +func (c *messengerClient) Notify(ctx context.Context, in *NotifyRequest, opts ...grpc.CallOption) (*NotifyResponse, error) { + out := new(NotifyResponse) + err := c.cc.Invoke(ctx, "/proto.Messenger/Notify", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MessengerServer is the server API for Messenger service. +type MessengerServer interface { + Notify(context.Context, *NotifyRequest) (*NotifyResponse, error) +} + +// UnimplementedMessengerServer can be embedded to have forward compatible implementations. +type UnimplementedMessengerServer struct { +} + +func (*UnimplementedMessengerServer) Notify(ctx context.Context, req *NotifyRequest) (*NotifyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Notify not implemented") +} + +func RegisterMessengerServer(s *grpc.Server, srv MessengerServer) { + s.RegisterService(&_Messenger_serviceDesc, srv) +} + +func _Messenger_Notify_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(NotifyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MessengerServer).Notify(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Messenger/Notify", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MessengerServer).Notify(ctx, req.(*NotifyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Messenger_serviceDesc = grpc.ServiceDesc{ + ServiceName: "proto.Messenger", + HandlerType: (*MessengerServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Notify", + Handler: _Messenger_Notify_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "messenger.proto", +} diff --git a/vms/rpcchainvm/messenger/proto/messenger.proto b/vms/rpcchainvm/messenger/proto/messenger.proto new file mode 100644 index 0000000..b1cb02b --- /dev/null +++ b/vms/rpcchainvm/messenger/proto/messenger.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package proto; + +message NotifyRequest { + uint32 message = 1; +} + +message NotifyResponse {} + +service Messenger { + rpc Notify(NotifyRequest) returns (NotifyResponse); +} \ No newline at end of file diff --git a/vms/rpcchainvm/proto/vm.pb.go b/vms/rpcchainvm/proto/vm.pb.go new file mode 100644 index 0000000..f39e89d --- /dev/null +++ b/vms/rpcchainvm/proto/vm.pb.go @@ -0,0 +1,1433 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: vm.proto + +package proto + +import ( + context "context" + fmt "fmt" + proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type InitializeRequest struct { + DbServer uint32 `protobuf:"varint,1,opt,name=dbServer,proto3" json:"dbServer,omitempty"` + GenesisBytes []byte `protobuf:"bytes,2,opt,name=genesisBytes,proto3" json:"genesisBytes,omitempty"` + EngineServer uint32 `protobuf:"varint,3,opt,name=engineServer,proto3" json:"engineServer,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *InitializeRequest) Reset() { *m = InitializeRequest{} } +func (m *InitializeRequest) String() string { return proto.CompactTextString(m) } +func (*InitializeRequest) ProtoMessage() {} +func (*InitializeRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{0} +} + +func (m *InitializeRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_InitializeRequest.Unmarshal(m, b) +} +func (m *InitializeRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_InitializeRequest.Marshal(b, m, deterministic) +} +func (m *InitializeRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_InitializeRequest.Merge(m, src) +} +func (m *InitializeRequest) XXX_Size() int { + return xxx_messageInfo_InitializeRequest.Size(m) +} +func (m *InitializeRequest) XXX_DiscardUnknown() { + xxx_messageInfo_InitializeRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_InitializeRequest proto.InternalMessageInfo + +func (m *InitializeRequest) GetDbServer() uint32 { + if m != nil { + return m.DbServer + } + return 0 +} + +func (m *InitializeRequest) GetGenesisBytes() []byte { + if m != nil { + return m.GenesisBytes + } + return nil +} + +func (m *InitializeRequest) GetEngineServer() uint32 { + if m != nil { + return m.EngineServer + } + return 0 +} + +type InitializeResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *InitializeResponse) Reset() { *m = InitializeResponse{} } +func (m *InitializeResponse) String() string { return proto.CompactTextString(m) } +func (*InitializeResponse) ProtoMessage() {} +func (*InitializeResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{1} +} + +func (m *InitializeResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_InitializeResponse.Unmarshal(m, b) +} +func (m *InitializeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_InitializeResponse.Marshal(b, m, deterministic) +} +func (m *InitializeResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_InitializeResponse.Merge(m, src) +} +func (m *InitializeResponse) XXX_Size() int { + return xxx_messageInfo_InitializeResponse.Size(m) +} +func (m *InitializeResponse) XXX_DiscardUnknown() { + xxx_messageInfo_InitializeResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_InitializeResponse proto.InternalMessageInfo + +type ShutdownRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ShutdownRequest) Reset() { *m = ShutdownRequest{} } +func (m *ShutdownRequest) String() string { return proto.CompactTextString(m) } +func (*ShutdownRequest) ProtoMessage() {} +func (*ShutdownRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{2} +} + +func (m *ShutdownRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ShutdownRequest.Unmarshal(m, b) +} +func (m *ShutdownRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ShutdownRequest.Marshal(b, m, deterministic) +} +func (m *ShutdownRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ShutdownRequest.Merge(m, src) +} +func (m *ShutdownRequest) XXX_Size() int { + return xxx_messageInfo_ShutdownRequest.Size(m) +} +func (m *ShutdownRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ShutdownRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ShutdownRequest proto.InternalMessageInfo + +type ShutdownResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ShutdownResponse) Reset() { *m = ShutdownResponse{} } +func (m *ShutdownResponse) String() string { return proto.CompactTextString(m) } +func (*ShutdownResponse) ProtoMessage() {} +func (*ShutdownResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{3} +} + +func (m *ShutdownResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ShutdownResponse.Unmarshal(m, b) +} +func (m *ShutdownResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ShutdownResponse.Marshal(b, m, deterministic) +} +func (m *ShutdownResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ShutdownResponse.Merge(m, src) +} +func (m *ShutdownResponse) XXX_Size() int { + return xxx_messageInfo_ShutdownResponse.Size(m) +} +func (m *ShutdownResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ShutdownResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ShutdownResponse proto.InternalMessageInfo + +type CreateHandlersRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateHandlersRequest) Reset() { *m = CreateHandlersRequest{} } +func (m *CreateHandlersRequest) String() string { return proto.CompactTextString(m) } +func (*CreateHandlersRequest) ProtoMessage() {} +func (*CreateHandlersRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{4} +} + +func (m *CreateHandlersRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateHandlersRequest.Unmarshal(m, b) +} +func (m *CreateHandlersRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateHandlersRequest.Marshal(b, m, deterministic) +} +func (m *CreateHandlersRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateHandlersRequest.Merge(m, src) +} +func (m *CreateHandlersRequest) XXX_Size() int { + return xxx_messageInfo_CreateHandlersRequest.Size(m) +} +func (m *CreateHandlersRequest) XXX_DiscardUnknown() { + xxx_messageInfo_CreateHandlersRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateHandlersRequest proto.InternalMessageInfo + +type CreateHandlersResponse struct { + Handlers []*Handler `protobuf:"bytes,1,rep,name=handlers,proto3" json:"handlers,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateHandlersResponse) Reset() { *m = CreateHandlersResponse{} } +func (m *CreateHandlersResponse) String() string { return proto.CompactTextString(m) } +func (*CreateHandlersResponse) ProtoMessage() {} +func (*CreateHandlersResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{5} +} + +func (m *CreateHandlersResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateHandlersResponse.Unmarshal(m, b) +} +func (m *CreateHandlersResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateHandlersResponse.Marshal(b, m, deterministic) +} +func (m *CreateHandlersResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateHandlersResponse.Merge(m, src) +} +func (m *CreateHandlersResponse) XXX_Size() int { + return xxx_messageInfo_CreateHandlersResponse.Size(m) +} +func (m *CreateHandlersResponse) XXX_DiscardUnknown() { + xxx_messageInfo_CreateHandlersResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateHandlersResponse proto.InternalMessageInfo + +func (m *CreateHandlersResponse) GetHandlers() []*Handler { + if m != nil { + return m.Handlers + } + return nil +} + +type Handler struct { + Prefix string `protobuf:"bytes,1,opt,name=prefix,proto3" json:"prefix,omitempty"` + LockOptions uint32 `protobuf:"varint,2,opt,name=lockOptions,proto3" json:"lockOptions,omitempty"` + Server uint32 `protobuf:"varint,3,opt,name=server,proto3" json:"server,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Handler) Reset() { *m = Handler{} } +func (m *Handler) String() string { return proto.CompactTextString(m) } +func (*Handler) ProtoMessage() {} +func (*Handler) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{6} +} + +func (m *Handler) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Handler.Unmarshal(m, b) +} +func (m *Handler) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Handler.Marshal(b, m, deterministic) +} +func (m *Handler) XXX_Merge(src proto.Message) { + xxx_messageInfo_Handler.Merge(m, src) +} +func (m *Handler) XXX_Size() int { + return xxx_messageInfo_Handler.Size(m) +} +func (m *Handler) XXX_DiscardUnknown() { + xxx_messageInfo_Handler.DiscardUnknown(m) +} + +var xxx_messageInfo_Handler proto.InternalMessageInfo + +func (m *Handler) GetPrefix() string { + if m != nil { + return m.Prefix + } + return "" +} + +func (m *Handler) GetLockOptions() uint32 { + if m != nil { + return m.LockOptions + } + return 0 +} + +func (m *Handler) GetServer() uint32 { + if m != nil { + return m.Server + } + return 0 +} + +type BuildBlockRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *BuildBlockRequest) Reset() { *m = BuildBlockRequest{} } +func (m *BuildBlockRequest) String() string { return proto.CompactTextString(m) } +func (*BuildBlockRequest) ProtoMessage() {} +func (*BuildBlockRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{7} +} + +func (m *BuildBlockRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_BuildBlockRequest.Unmarshal(m, b) +} +func (m *BuildBlockRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_BuildBlockRequest.Marshal(b, m, deterministic) +} +func (m *BuildBlockRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_BuildBlockRequest.Merge(m, src) +} +func (m *BuildBlockRequest) XXX_Size() int { + return xxx_messageInfo_BuildBlockRequest.Size(m) +} +func (m *BuildBlockRequest) XXX_DiscardUnknown() { + xxx_messageInfo_BuildBlockRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_BuildBlockRequest proto.InternalMessageInfo + +type BuildBlockResponse struct { + Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + ParentID []byte `protobuf:"bytes,2,opt,name=parentID,proto3" json:"parentID,omitempty"` + Bytes []byte `protobuf:"bytes,3,opt,name=bytes,proto3" json:"bytes,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *BuildBlockResponse) Reset() { *m = BuildBlockResponse{} } +func (m *BuildBlockResponse) String() string { return proto.CompactTextString(m) } +func (*BuildBlockResponse) ProtoMessage() {} +func (*BuildBlockResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{8} +} + +func (m *BuildBlockResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_BuildBlockResponse.Unmarshal(m, b) +} +func (m *BuildBlockResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_BuildBlockResponse.Marshal(b, m, deterministic) +} +func (m *BuildBlockResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_BuildBlockResponse.Merge(m, src) +} +func (m *BuildBlockResponse) XXX_Size() int { + return xxx_messageInfo_BuildBlockResponse.Size(m) +} +func (m *BuildBlockResponse) XXX_DiscardUnknown() { + xxx_messageInfo_BuildBlockResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_BuildBlockResponse proto.InternalMessageInfo + +func (m *BuildBlockResponse) GetId() []byte { + if m != nil { + return m.Id + } + return nil +} + +func (m *BuildBlockResponse) GetParentID() []byte { + if m != nil { + return m.ParentID + } + return nil +} + +func (m *BuildBlockResponse) GetBytes() []byte { + if m != nil { + return m.Bytes + } + return nil +} + +type ParseBlockRequest struct { + Bytes []byte `protobuf:"bytes,1,opt,name=bytes,proto3" json:"bytes,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ParseBlockRequest) Reset() { *m = ParseBlockRequest{} } +func (m *ParseBlockRequest) String() string { return proto.CompactTextString(m) } +func (*ParseBlockRequest) ProtoMessage() {} +func (*ParseBlockRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{9} +} + +func (m *ParseBlockRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ParseBlockRequest.Unmarshal(m, b) +} +func (m *ParseBlockRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ParseBlockRequest.Marshal(b, m, deterministic) +} +func (m *ParseBlockRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ParseBlockRequest.Merge(m, src) +} +func (m *ParseBlockRequest) XXX_Size() int { + return xxx_messageInfo_ParseBlockRequest.Size(m) +} +func (m *ParseBlockRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ParseBlockRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ParseBlockRequest proto.InternalMessageInfo + +func (m *ParseBlockRequest) GetBytes() []byte { + if m != nil { + return m.Bytes + } + return nil +} + +type ParseBlockResponse struct { + Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + ParentID []byte `protobuf:"bytes,2,opt,name=parentID,proto3" json:"parentID,omitempty"` + Status uint32 `protobuf:"varint,3,opt,name=status,proto3" json:"status,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ParseBlockResponse) Reset() { *m = ParseBlockResponse{} } +func (m *ParseBlockResponse) String() string { return proto.CompactTextString(m) } +func (*ParseBlockResponse) ProtoMessage() {} +func (*ParseBlockResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{10} +} + +func (m *ParseBlockResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ParseBlockResponse.Unmarshal(m, b) +} +func (m *ParseBlockResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ParseBlockResponse.Marshal(b, m, deterministic) +} +func (m *ParseBlockResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ParseBlockResponse.Merge(m, src) +} +func (m *ParseBlockResponse) XXX_Size() int { + return xxx_messageInfo_ParseBlockResponse.Size(m) +} +func (m *ParseBlockResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ParseBlockResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ParseBlockResponse proto.InternalMessageInfo + +func (m *ParseBlockResponse) GetId() []byte { + if m != nil { + return m.Id + } + return nil +} + +func (m *ParseBlockResponse) GetParentID() []byte { + if m != nil { + return m.ParentID + } + return nil +} + +func (m *ParseBlockResponse) GetStatus() uint32 { + if m != nil { + return m.Status + } + return 0 +} + +type GetBlockRequest struct { + Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetBlockRequest) Reset() { *m = GetBlockRequest{} } +func (m *GetBlockRequest) String() string { return proto.CompactTextString(m) } +func (*GetBlockRequest) ProtoMessage() {} +func (*GetBlockRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{11} +} + +func (m *GetBlockRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetBlockRequest.Unmarshal(m, b) +} +func (m *GetBlockRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetBlockRequest.Marshal(b, m, deterministic) +} +func (m *GetBlockRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetBlockRequest.Merge(m, src) +} +func (m *GetBlockRequest) XXX_Size() int { + return xxx_messageInfo_GetBlockRequest.Size(m) +} +func (m *GetBlockRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GetBlockRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GetBlockRequest proto.InternalMessageInfo + +func (m *GetBlockRequest) GetId() []byte { + if m != nil { + return m.Id + } + return nil +} + +type GetBlockResponse struct { + ParentID []byte `protobuf:"bytes,1,opt,name=parentID,proto3" json:"parentID,omitempty"` + Bytes []byte `protobuf:"bytes,2,opt,name=bytes,proto3" json:"bytes,omitempty"` + Status uint32 `protobuf:"varint,3,opt,name=status,proto3" json:"status,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetBlockResponse) Reset() { *m = GetBlockResponse{} } +func (m *GetBlockResponse) String() string { return proto.CompactTextString(m) } +func (*GetBlockResponse) ProtoMessage() {} +func (*GetBlockResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{12} +} + +func (m *GetBlockResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetBlockResponse.Unmarshal(m, b) +} +func (m *GetBlockResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetBlockResponse.Marshal(b, m, deterministic) +} +func (m *GetBlockResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetBlockResponse.Merge(m, src) +} +func (m *GetBlockResponse) XXX_Size() int { + return xxx_messageInfo_GetBlockResponse.Size(m) +} +func (m *GetBlockResponse) XXX_DiscardUnknown() { + xxx_messageInfo_GetBlockResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_GetBlockResponse proto.InternalMessageInfo + +func (m *GetBlockResponse) GetParentID() []byte { + if m != nil { + return m.ParentID + } + return nil +} + +func (m *GetBlockResponse) GetBytes() []byte { + if m != nil { + return m.Bytes + } + return nil +} + +func (m *GetBlockResponse) GetStatus() uint32 { + if m != nil { + return m.Status + } + return 0 +} + +type SetPreferenceRequest struct { + Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SetPreferenceRequest) Reset() { *m = SetPreferenceRequest{} } +func (m *SetPreferenceRequest) String() string { return proto.CompactTextString(m) } +func (*SetPreferenceRequest) ProtoMessage() {} +func (*SetPreferenceRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{13} +} + +func (m *SetPreferenceRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SetPreferenceRequest.Unmarshal(m, b) +} +func (m *SetPreferenceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SetPreferenceRequest.Marshal(b, m, deterministic) +} +func (m *SetPreferenceRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_SetPreferenceRequest.Merge(m, src) +} +func (m *SetPreferenceRequest) XXX_Size() int { + return xxx_messageInfo_SetPreferenceRequest.Size(m) +} +func (m *SetPreferenceRequest) XXX_DiscardUnknown() { + xxx_messageInfo_SetPreferenceRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_SetPreferenceRequest proto.InternalMessageInfo + +func (m *SetPreferenceRequest) GetId() []byte { + if m != nil { + return m.Id + } + return nil +} + +type SetPreferenceResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SetPreferenceResponse) Reset() { *m = SetPreferenceResponse{} } +func (m *SetPreferenceResponse) String() string { return proto.CompactTextString(m) } +func (*SetPreferenceResponse) ProtoMessage() {} +func (*SetPreferenceResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{14} +} + +func (m *SetPreferenceResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SetPreferenceResponse.Unmarshal(m, b) +} +func (m *SetPreferenceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SetPreferenceResponse.Marshal(b, m, deterministic) +} +func (m *SetPreferenceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_SetPreferenceResponse.Merge(m, src) +} +func (m *SetPreferenceResponse) XXX_Size() int { + return xxx_messageInfo_SetPreferenceResponse.Size(m) +} +func (m *SetPreferenceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_SetPreferenceResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_SetPreferenceResponse proto.InternalMessageInfo + +type LastAcceptedRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *LastAcceptedRequest) Reset() { *m = LastAcceptedRequest{} } +func (m *LastAcceptedRequest) String() string { return proto.CompactTextString(m) } +func (*LastAcceptedRequest) ProtoMessage() {} +func (*LastAcceptedRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{15} +} + +func (m *LastAcceptedRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_LastAcceptedRequest.Unmarshal(m, b) +} +func (m *LastAcceptedRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_LastAcceptedRequest.Marshal(b, m, deterministic) +} +func (m *LastAcceptedRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_LastAcceptedRequest.Merge(m, src) +} +func (m *LastAcceptedRequest) XXX_Size() int { + return xxx_messageInfo_LastAcceptedRequest.Size(m) +} +func (m *LastAcceptedRequest) XXX_DiscardUnknown() { + xxx_messageInfo_LastAcceptedRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_LastAcceptedRequest proto.InternalMessageInfo + +type LastAcceptedResponse struct { + Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *LastAcceptedResponse) Reset() { *m = LastAcceptedResponse{} } +func (m *LastAcceptedResponse) String() string { return proto.CompactTextString(m) } +func (*LastAcceptedResponse) ProtoMessage() {} +func (*LastAcceptedResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{16} +} + +func (m *LastAcceptedResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_LastAcceptedResponse.Unmarshal(m, b) +} +func (m *LastAcceptedResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_LastAcceptedResponse.Marshal(b, m, deterministic) +} +func (m *LastAcceptedResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_LastAcceptedResponse.Merge(m, src) +} +func (m *LastAcceptedResponse) XXX_Size() int { + return xxx_messageInfo_LastAcceptedResponse.Size(m) +} +func (m *LastAcceptedResponse) XXX_DiscardUnknown() { + xxx_messageInfo_LastAcceptedResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_LastAcceptedResponse proto.InternalMessageInfo + +func (m *LastAcceptedResponse) GetId() []byte { + if m != nil { + return m.Id + } + return nil +} + +type BlockVerifyRequest struct { + Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *BlockVerifyRequest) Reset() { *m = BlockVerifyRequest{} } +func (m *BlockVerifyRequest) String() string { return proto.CompactTextString(m) } +func (*BlockVerifyRequest) ProtoMessage() {} +func (*BlockVerifyRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{17} +} + +func (m *BlockVerifyRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_BlockVerifyRequest.Unmarshal(m, b) +} +func (m *BlockVerifyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_BlockVerifyRequest.Marshal(b, m, deterministic) +} +func (m *BlockVerifyRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlockVerifyRequest.Merge(m, src) +} +func (m *BlockVerifyRequest) XXX_Size() int { + return xxx_messageInfo_BlockVerifyRequest.Size(m) +} +func (m *BlockVerifyRequest) XXX_DiscardUnknown() { + xxx_messageInfo_BlockVerifyRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_BlockVerifyRequest proto.InternalMessageInfo + +func (m *BlockVerifyRequest) GetId() []byte { + if m != nil { + return m.Id + } + return nil +} + +type BlockVerifyResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *BlockVerifyResponse) Reset() { *m = BlockVerifyResponse{} } +func (m *BlockVerifyResponse) String() string { return proto.CompactTextString(m) } +func (*BlockVerifyResponse) ProtoMessage() {} +func (*BlockVerifyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{18} +} + +func (m *BlockVerifyResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_BlockVerifyResponse.Unmarshal(m, b) +} +func (m *BlockVerifyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_BlockVerifyResponse.Marshal(b, m, deterministic) +} +func (m *BlockVerifyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlockVerifyResponse.Merge(m, src) +} +func (m *BlockVerifyResponse) XXX_Size() int { + return xxx_messageInfo_BlockVerifyResponse.Size(m) +} +func (m *BlockVerifyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_BlockVerifyResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_BlockVerifyResponse proto.InternalMessageInfo + +type BlockAcceptRequest struct { + Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *BlockAcceptRequest) Reset() { *m = BlockAcceptRequest{} } +func (m *BlockAcceptRequest) String() string { return proto.CompactTextString(m) } +func (*BlockAcceptRequest) ProtoMessage() {} +func (*BlockAcceptRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{19} +} + +func (m *BlockAcceptRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_BlockAcceptRequest.Unmarshal(m, b) +} +func (m *BlockAcceptRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_BlockAcceptRequest.Marshal(b, m, deterministic) +} +func (m *BlockAcceptRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlockAcceptRequest.Merge(m, src) +} +func (m *BlockAcceptRequest) XXX_Size() int { + return xxx_messageInfo_BlockAcceptRequest.Size(m) +} +func (m *BlockAcceptRequest) XXX_DiscardUnknown() { + xxx_messageInfo_BlockAcceptRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_BlockAcceptRequest proto.InternalMessageInfo + +func (m *BlockAcceptRequest) GetId() []byte { + if m != nil { + return m.Id + } + return nil +} + +type BlockAcceptResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *BlockAcceptResponse) Reset() { *m = BlockAcceptResponse{} } +func (m *BlockAcceptResponse) String() string { return proto.CompactTextString(m) } +func (*BlockAcceptResponse) ProtoMessage() {} +func (*BlockAcceptResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{20} +} + +func (m *BlockAcceptResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_BlockAcceptResponse.Unmarshal(m, b) +} +func (m *BlockAcceptResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_BlockAcceptResponse.Marshal(b, m, deterministic) +} +func (m *BlockAcceptResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlockAcceptResponse.Merge(m, src) +} +func (m *BlockAcceptResponse) XXX_Size() int { + return xxx_messageInfo_BlockAcceptResponse.Size(m) +} +func (m *BlockAcceptResponse) XXX_DiscardUnknown() { + xxx_messageInfo_BlockAcceptResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_BlockAcceptResponse proto.InternalMessageInfo + +type BlockRejectRequest struct { + Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *BlockRejectRequest) Reset() { *m = BlockRejectRequest{} } +func (m *BlockRejectRequest) String() string { return proto.CompactTextString(m) } +func (*BlockRejectRequest) ProtoMessage() {} +func (*BlockRejectRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{21} +} + +func (m *BlockRejectRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_BlockRejectRequest.Unmarshal(m, b) +} +func (m *BlockRejectRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_BlockRejectRequest.Marshal(b, m, deterministic) +} +func (m *BlockRejectRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlockRejectRequest.Merge(m, src) +} +func (m *BlockRejectRequest) XXX_Size() int { + return xxx_messageInfo_BlockRejectRequest.Size(m) +} +func (m *BlockRejectRequest) XXX_DiscardUnknown() { + xxx_messageInfo_BlockRejectRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_BlockRejectRequest proto.InternalMessageInfo + +func (m *BlockRejectRequest) GetId() []byte { + if m != nil { + return m.Id + } + return nil +} + +type BlockRejectResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *BlockRejectResponse) Reset() { *m = BlockRejectResponse{} } +func (m *BlockRejectResponse) String() string { return proto.CompactTextString(m) } +func (*BlockRejectResponse) ProtoMessage() {} +func (*BlockRejectResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_cab246c8c7c5372d, []int{22} +} + +func (m *BlockRejectResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_BlockRejectResponse.Unmarshal(m, b) +} +func (m *BlockRejectResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_BlockRejectResponse.Marshal(b, m, deterministic) +} +func (m *BlockRejectResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlockRejectResponse.Merge(m, src) +} +func (m *BlockRejectResponse) XXX_Size() int { + return xxx_messageInfo_BlockRejectResponse.Size(m) +} +func (m *BlockRejectResponse) XXX_DiscardUnknown() { + xxx_messageInfo_BlockRejectResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_BlockRejectResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*InitializeRequest)(nil), "proto.InitializeRequest") + proto.RegisterType((*InitializeResponse)(nil), "proto.InitializeResponse") + proto.RegisterType((*ShutdownRequest)(nil), "proto.ShutdownRequest") + proto.RegisterType((*ShutdownResponse)(nil), "proto.ShutdownResponse") + proto.RegisterType((*CreateHandlersRequest)(nil), "proto.CreateHandlersRequest") + proto.RegisterType((*CreateHandlersResponse)(nil), "proto.CreateHandlersResponse") + proto.RegisterType((*Handler)(nil), "proto.Handler") + proto.RegisterType((*BuildBlockRequest)(nil), "proto.BuildBlockRequest") + proto.RegisterType((*BuildBlockResponse)(nil), "proto.BuildBlockResponse") + proto.RegisterType((*ParseBlockRequest)(nil), "proto.ParseBlockRequest") + proto.RegisterType((*ParseBlockResponse)(nil), "proto.ParseBlockResponse") + proto.RegisterType((*GetBlockRequest)(nil), "proto.GetBlockRequest") + proto.RegisterType((*GetBlockResponse)(nil), "proto.GetBlockResponse") + proto.RegisterType((*SetPreferenceRequest)(nil), "proto.SetPreferenceRequest") + proto.RegisterType((*SetPreferenceResponse)(nil), "proto.SetPreferenceResponse") + proto.RegisterType((*LastAcceptedRequest)(nil), "proto.LastAcceptedRequest") + proto.RegisterType((*LastAcceptedResponse)(nil), "proto.LastAcceptedResponse") + proto.RegisterType((*BlockVerifyRequest)(nil), "proto.BlockVerifyRequest") + proto.RegisterType((*BlockVerifyResponse)(nil), "proto.BlockVerifyResponse") + proto.RegisterType((*BlockAcceptRequest)(nil), "proto.BlockAcceptRequest") + proto.RegisterType((*BlockAcceptResponse)(nil), "proto.BlockAcceptResponse") + proto.RegisterType((*BlockRejectRequest)(nil), "proto.BlockRejectRequest") + proto.RegisterType((*BlockRejectResponse)(nil), "proto.BlockRejectResponse") +} + +func init() { proto.RegisterFile("vm.proto", fileDescriptor_cab246c8c7c5372d) } + +var fileDescriptor_cab246c8c7c5372d = []byte{ + // 610 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x4b, 0x6f, 0xd3, 0x40, + 0x10, 0x96, 0x53, 0xb5, 0x84, 0xc9, 0xa3, 0xcd, 0xe6, 0x89, 0x5b, 0xa4, 0x60, 0xa1, 0x2a, 0x70, + 0xe8, 0xa1, 0x1c, 0x7b, 0x4a, 0x88, 0x54, 0x8a, 0xa8, 0xa8, 0x1c, 0x29, 0x42, 0x82, 0x8b, 0x13, + 0x4f, 0x5a, 0x43, 0xb0, 0x8d, 0x77, 0xd3, 0x52, 0xfe, 0x3b, 0x12, 0x8a, 0x3d, 0x5e, 0xef, 0xda, + 0x8e, 0x2a, 0x71, 0xb2, 0x66, 0xe6, 0x9b, 0x6f, 0x1e, 0x3b, 0x9f, 0xa1, 0x7a, 0xff, 0xf3, 0x2c, + 0x8c, 0x02, 0x11, 0xb0, 0xfd, 0xf8, 0x63, 0x3d, 0x40, 0xeb, 0xca, 0xf7, 0x84, 0xe7, 0xac, 0xbd, + 0x3f, 0x68, 0xe3, 0xaf, 0x0d, 0x72, 0xc1, 0x4c, 0xa8, 0xba, 0x8b, 0x19, 0x46, 0xf7, 0x18, 0x0d, + 0x8c, 0xa1, 0x31, 0x6a, 0xd8, 0xd2, 0x66, 0x16, 0xd4, 0x6f, 0xd1, 0x47, 0xee, 0xf1, 0xc9, 0xa3, + 0x40, 0x3e, 0xa8, 0x0c, 0x8d, 0x51, 0xdd, 0xd6, 0x7c, 0x5b, 0x0c, 0xfa, 0xb7, 0x9e, 0x8f, 0xc4, + 0xb1, 0x17, 0x73, 0x68, 0x3e, 0xab, 0x03, 0x4c, 0x2d, 0xcc, 0xc3, 0xc0, 0xe7, 0x68, 0xb5, 0xe0, + 0x70, 0x76, 0xb7, 0x11, 0x6e, 0xf0, 0xe0, 0x53, 0x33, 0x16, 0x83, 0xa3, 0xcc, 0x45, 0xb0, 0x3e, + 0x74, 0xdf, 0x47, 0xe8, 0x08, 0xfc, 0xe0, 0xf8, 0xee, 0x1a, 0x23, 0x9e, 0x82, 0xa7, 0xd0, 0xcb, + 0x07, 0x92, 0x14, 0xf6, 0x16, 0xaa, 0x77, 0xe4, 0x1b, 0x18, 0xc3, 0xbd, 0x51, 0xed, 0xbc, 0x99, + 0x6c, 0xe2, 0x8c, 0xa0, 0xb6, 0x8c, 0x5b, 0x5f, 0xe1, 0x19, 0x39, 0x59, 0x0f, 0x0e, 0xc2, 0x08, + 0x57, 0xde, 0xef, 0x78, 0x11, 0xcf, 0x6d, 0xb2, 0xd8, 0x10, 0x6a, 0xeb, 0x60, 0xf9, 0xe3, 0x73, + 0x28, 0xbc, 0xc0, 0x4f, 0xb6, 0xd0, 0xb0, 0x55, 0xd7, 0x36, 0x93, 0xab, 0xe3, 0x93, 0x65, 0xb5, + 0xa1, 0x35, 0xd9, 0x78, 0x6b, 0x77, 0xb2, 0x05, 0xa7, 0x7d, 0xcf, 0x81, 0xa9, 0x4e, 0xea, 0xb9, + 0x09, 0x15, 0xcf, 0x8d, 0x0b, 0xd7, 0xed, 0x8a, 0xe7, 0x6e, 0xdf, 0x25, 0x74, 0x22, 0xf4, 0xc5, + 0xd5, 0x94, 0xf6, 0x2e, 0x6d, 0xd6, 0x81, 0xfd, 0x45, 0xfc, 0x20, 0x7b, 0x71, 0x20, 0x31, 0xac, + 0x37, 0xd0, 0xba, 0x71, 0x22, 0x8e, 0x6a, 0xb1, 0x0c, 0x6a, 0xa8, 0xd0, 0x2f, 0xc0, 0x54, 0xe8, + 0x7f, 0xb4, 0xb0, 0x9d, 0x58, 0x38, 0x62, 0xc3, 0xe5, 0xc4, 0xb1, 0x65, 0xbd, 0x82, 0xc3, 0x4b, + 0x14, 0x5a, 0x0b, 0x39, 0x5a, 0xeb, 0x1b, 0x1c, 0x65, 0x10, 0x2a, 0xad, 0x96, 0x32, 0x76, 0x4d, + 0x5b, 0x51, 0x46, 0xd8, 0xd9, 0xc0, 0x29, 0x74, 0x66, 0x28, 0x6e, 0x22, 0x5c, 0x61, 0x84, 0xfe, + 0x12, 0x77, 0x75, 0xd1, 0x87, 0x6e, 0x0e, 0x47, 0xf7, 0xd6, 0x85, 0xf6, 0x27, 0x87, 0x8b, 0xf1, + 0x72, 0x89, 0xa1, 0x40, 0x37, 0x7d, 0xb5, 0x53, 0xe8, 0xe8, 0xee, 0xf2, 0xa5, 0x59, 0xaf, 0x81, + 0xc5, 0xa3, 0xcd, 0x31, 0xf2, 0x56, 0x8f, 0xbb, 0xaa, 0x77, 0xa1, 0xad, 0xa1, 0xa8, 0x76, 0x9a, + 0x9c, 0x54, 0x79, 0x2a, 0x39, 0x45, 0xe5, 0x92, 0x6d, 0xfc, 0x8e, 0xcb, 0x27, 0x93, 0x53, 0x54, + 0x92, 0x7c, 0xfe, 0x77, 0x1f, 0x2a, 0xf3, 0x6b, 0x36, 0x06, 0xc8, 0x94, 0xca, 0x06, 0xa4, 0x9a, + 0xc2, 0x5f, 0xc3, 0x7c, 0x51, 0x12, 0xa1, 0x85, 0x5c, 0x40, 0x35, 0xd5, 0x30, 0xeb, 0x11, 0x2c, + 0xa7, 0x73, 0xb3, 0x5f, 0xf0, 0x53, 0xf2, 0x35, 0x34, 0x75, 0x4d, 0xb3, 0x13, 0x82, 0x96, 0xfe, + 0x03, 0xcc, 0x97, 0x3b, 0xa2, 0x44, 0x37, 0x06, 0xc8, 0xa4, 0x26, 0xc7, 0x29, 0x48, 0x52, 0x8e, + 0x53, 0xa2, 0xcb, 0x31, 0x40, 0x26, 0x15, 0x49, 0x51, 0x10, 0x9a, 0xa4, 0x28, 0xd1, 0xd5, 0x05, + 0x54, 0xd3, 0x83, 0x97, 0x1b, 0xc9, 0x89, 0x44, 0x6e, 0xa4, 0xa0, 0x8c, 0x8f, 0xd0, 0xd0, 0xee, + 0x94, 0x1d, 0xa7, 0xbb, 0x2b, 0xb9, 0x72, 0xf3, 0xa4, 0x3c, 0x48, 0x5c, 0x97, 0x50, 0x57, 0x6f, + 0x98, 0x99, 0x84, 0x2e, 0xb9, 0x77, 0xf3, 0xb8, 0x34, 0x46, 0x44, 0x53, 0xa8, 0x29, 0xe7, 0xcb, + 0xe4, 0xfa, 0x0a, 0x87, 0x6f, 0x9a, 0x65, 0xa1, 0x1c, 0x4b, 0x42, 0xaf, 0xb3, 0x68, 0x0a, 0xd0, + 0x59, 0xf4, 0xb3, 0x97, 0x2c, 0xc9, 0x41, 0xeb, 0x2c, 0x9a, 0x14, 0x74, 0x16, 0xfd, 0xfe, 0x17, + 0x07, 0x71, 0xe8, 0xdd, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x10, 0x57, 0x73, 0x31, 0x35, 0x07, + 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConnInterface + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion6 + +// VMClient is the client API for VM service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type VMClient interface { + Initialize(ctx context.Context, in *InitializeRequest, opts ...grpc.CallOption) (*InitializeResponse, error) + Shutdown(ctx context.Context, in *ShutdownRequest, opts ...grpc.CallOption) (*ShutdownResponse, error) + CreateHandlers(ctx context.Context, in *CreateHandlersRequest, opts ...grpc.CallOption) (*CreateHandlersResponse, error) + BuildBlock(ctx context.Context, in *BuildBlockRequest, opts ...grpc.CallOption) (*BuildBlockResponse, error) + ParseBlock(ctx context.Context, in *ParseBlockRequest, opts ...grpc.CallOption) (*ParseBlockResponse, error) + GetBlock(ctx context.Context, in *GetBlockRequest, opts ...grpc.CallOption) (*GetBlockResponse, error) + SetPreference(ctx context.Context, in *SetPreferenceRequest, opts ...grpc.CallOption) (*SetPreferenceResponse, error) + LastAccepted(ctx context.Context, in *LastAcceptedRequest, opts ...grpc.CallOption) (*LastAcceptedResponse, error) + BlockVerify(ctx context.Context, in *BlockVerifyRequest, opts ...grpc.CallOption) (*BlockVerifyResponse, error) + BlockAccept(ctx context.Context, in *BlockAcceptRequest, opts ...grpc.CallOption) (*BlockAcceptResponse, error) + BlockReject(ctx context.Context, in *BlockRejectRequest, opts ...grpc.CallOption) (*BlockRejectResponse, error) +} + +type vMClient struct { + cc grpc.ClientConnInterface +} + +func NewVMClient(cc grpc.ClientConnInterface) VMClient { + return &vMClient{cc} +} + +func (c *vMClient) Initialize(ctx context.Context, in *InitializeRequest, opts ...grpc.CallOption) (*InitializeResponse, error) { + out := new(InitializeResponse) + err := c.cc.Invoke(ctx, "/proto.VM/Initialize", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *vMClient) Shutdown(ctx context.Context, in *ShutdownRequest, opts ...grpc.CallOption) (*ShutdownResponse, error) { + out := new(ShutdownResponse) + err := c.cc.Invoke(ctx, "/proto.VM/Shutdown", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *vMClient) CreateHandlers(ctx context.Context, in *CreateHandlersRequest, opts ...grpc.CallOption) (*CreateHandlersResponse, error) { + out := new(CreateHandlersResponse) + err := c.cc.Invoke(ctx, "/proto.VM/CreateHandlers", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *vMClient) BuildBlock(ctx context.Context, in *BuildBlockRequest, opts ...grpc.CallOption) (*BuildBlockResponse, error) { + out := new(BuildBlockResponse) + err := c.cc.Invoke(ctx, "/proto.VM/BuildBlock", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *vMClient) ParseBlock(ctx context.Context, in *ParseBlockRequest, opts ...grpc.CallOption) (*ParseBlockResponse, error) { + out := new(ParseBlockResponse) + err := c.cc.Invoke(ctx, "/proto.VM/ParseBlock", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *vMClient) GetBlock(ctx context.Context, in *GetBlockRequest, opts ...grpc.CallOption) (*GetBlockResponse, error) { + out := new(GetBlockResponse) + err := c.cc.Invoke(ctx, "/proto.VM/GetBlock", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *vMClient) SetPreference(ctx context.Context, in *SetPreferenceRequest, opts ...grpc.CallOption) (*SetPreferenceResponse, error) { + out := new(SetPreferenceResponse) + err := c.cc.Invoke(ctx, "/proto.VM/SetPreference", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *vMClient) LastAccepted(ctx context.Context, in *LastAcceptedRequest, opts ...grpc.CallOption) (*LastAcceptedResponse, error) { + out := new(LastAcceptedResponse) + err := c.cc.Invoke(ctx, "/proto.VM/LastAccepted", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *vMClient) BlockVerify(ctx context.Context, in *BlockVerifyRequest, opts ...grpc.CallOption) (*BlockVerifyResponse, error) { + out := new(BlockVerifyResponse) + err := c.cc.Invoke(ctx, "/proto.VM/BlockVerify", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *vMClient) BlockAccept(ctx context.Context, in *BlockAcceptRequest, opts ...grpc.CallOption) (*BlockAcceptResponse, error) { + out := new(BlockAcceptResponse) + err := c.cc.Invoke(ctx, "/proto.VM/BlockAccept", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *vMClient) BlockReject(ctx context.Context, in *BlockRejectRequest, opts ...grpc.CallOption) (*BlockRejectResponse, error) { + out := new(BlockRejectResponse) + err := c.cc.Invoke(ctx, "/proto.VM/BlockReject", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// VMServer is the server API for VM service. +type VMServer interface { + Initialize(context.Context, *InitializeRequest) (*InitializeResponse, error) + Shutdown(context.Context, *ShutdownRequest) (*ShutdownResponse, error) + CreateHandlers(context.Context, *CreateHandlersRequest) (*CreateHandlersResponse, error) + BuildBlock(context.Context, *BuildBlockRequest) (*BuildBlockResponse, error) + ParseBlock(context.Context, *ParseBlockRequest) (*ParseBlockResponse, error) + GetBlock(context.Context, *GetBlockRequest) (*GetBlockResponse, error) + SetPreference(context.Context, *SetPreferenceRequest) (*SetPreferenceResponse, error) + LastAccepted(context.Context, *LastAcceptedRequest) (*LastAcceptedResponse, error) + BlockVerify(context.Context, *BlockVerifyRequest) (*BlockVerifyResponse, error) + BlockAccept(context.Context, *BlockAcceptRequest) (*BlockAcceptResponse, error) + BlockReject(context.Context, *BlockRejectRequest) (*BlockRejectResponse, error) +} + +// UnimplementedVMServer can be embedded to have forward compatible implementations. +type UnimplementedVMServer struct { +} + +func (*UnimplementedVMServer) Initialize(ctx context.Context, req *InitializeRequest) (*InitializeResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Initialize not implemented") +} +func (*UnimplementedVMServer) Shutdown(ctx context.Context, req *ShutdownRequest) (*ShutdownResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Shutdown not implemented") +} +func (*UnimplementedVMServer) CreateHandlers(ctx context.Context, req *CreateHandlersRequest) (*CreateHandlersResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateHandlers not implemented") +} +func (*UnimplementedVMServer) BuildBlock(ctx context.Context, req *BuildBlockRequest) (*BuildBlockResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BuildBlock not implemented") +} +func (*UnimplementedVMServer) ParseBlock(ctx context.Context, req *ParseBlockRequest) (*ParseBlockResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ParseBlock not implemented") +} +func (*UnimplementedVMServer) GetBlock(ctx context.Context, req *GetBlockRequest) (*GetBlockResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBlock not implemented") +} +func (*UnimplementedVMServer) SetPreference(ctx context.Context, req *SetPreferenceRequest) (*SetPreferenceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SetPreference not implemented") +} +func (*UnimplementedVMServer) LastAccepted(ctx context.Context, req *LastAcceptedRequest) (*LastAcceptedResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method LastAccepted not implemented") +} +func (*UnimplementedVMServer) BlockVerify(ctx context.Context, req *BlockVerifyRequest) (*BlockVerifyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BlockVerify not implemented") +} +func (*UnimplementedVMServer) BlockAccept(ctx context.Context, req *BlockAcceptRequest) (*BlockAcceptResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BlockAccept not implemented") +} +func (*UnimplementedVMServer) BlockReject(ctx context.Context, req *BlockRejectRequest) (*BlockRejectResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BlockReject not implemented") +} + +func RegisterVMServer(s *grpc.Server, srv VMServer) { + s.RegisterService(&_VM_serviceDesc, srv) +} + +func _VM_Initialize_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(InitializeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VMServer).Initialize(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.VM/Initialize", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VMServer).Initialize(ctx, req.(*InitializeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _VM_Shutdown_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ShutdownRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VMServer).Shutdown(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.VM/Shutdown", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VMServer).Shutdown(ctx, req.(*ShutdownRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _VM_CreateHandlers_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateHandlersRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VMServer).CreateHandlers(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.VM/CreateHandlers", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VMServer).CreateHandlers(ctx, req.(*CreateHandlersRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _VM_BuildBlock_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BuildBlockRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VMServer).BuildBlock(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.VM/BuildBlock", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VMServer).BuildBlock(ctx, req.(*BuildBlockRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _VM_ParseBlock_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ParseBlockRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VMServer).ParseBlock(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.VM/ParseBlock", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VMServer).ParseBlock(ctx, req.(*ParseBlockRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _VM_GetBlock_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetBlockRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VMServer).GetBlock(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.VM/GetBlock", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VMServer).GetBlock(ctx, req.(*GetBlockRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _VM_SetPreference_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SetPreferenceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VMServer).SetPreference(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.VM/SetPreference", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VMServer).SetPreference(ctx, req.(*SetPreferenceRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _VM_LastAccepted_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LastAcceptedRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VMServer).LastAccepted(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.VM/LastAccepted", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VMServer).LastAccepted(ctx, req.(*LastAcceptedRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _VM_BlockVerify_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BlockVerifyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VMServer).BlockVerify(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.VM/BlockVerify", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VMServer).BlockVerify(ctx, req.(*BlockVerifyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _VM_BlockAccept_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BlockAcceptRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VMServer).BlockAccept(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.VM/BlockAccept", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VMServer).BlockAccept(ctx, req.(*BlockAcceptRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _VM_BlockReject_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BlockRejectRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VMServer).BlockReject(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.VM/BlockReject", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VMServer).BlockReject(ctx, req.(*BlockRejectRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _VM_serviceDesc = grpc.ServiceDesc{ + ServiceName: "proto.VM", + HandlerType: (*VMServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Initialize", + Handler: _VM_Initialize_Handler, + }, + { + MethodName: "Shutdown", + Handler: _VM_Shutdown_Handler, + }, + { + MethodName: "CreateHandlers", + Handler: _VM_CreateHandlers_Handler, + }, + { + MethodName: "BuildBlock", + Handler: _VM_BuildBlock_Handler, + }, + { + MethodName: "ParseBlock", + Handler: _VM_ParseBlock_Handler, + }, + { + MethodName: "GetBlock", + Handler: _VM_GetBlock_Handler, + }, + { + MethodName: "SetPreference", + Handler: _VM_SetPreference_Handler, + }, + { + MethodName: "LastAccepted", + Handler: _VM_LastAccepted_Handler, + }, + { + MethodName: "BlockVerify", + Handler: _VM_BlockVerify_Handler, + }, + { + MethodName: "BlockAccept", + Handler: _VM_BlockAccept_Handler, + }, + { + MethodName: "BlockReject", + Handler: _VM_BlockReject_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "vm.proto", +} diff --git a/vms/rpcchainvm/proto/vm.proto b/vms/rpcchainvm/proto/vm.proto new file mode 100644 index 0000000..649c66b --- /dev/null +++ b/vms/rpcchainvm/proto/vm.proto @@ -0,0 +1,100 @@ +syntax = "proto3"; +package proto; + +message InitializeRequest { + uint32 dbServer = 1; + bytes genesisBytes = 2; + uint32 engineServer = 3; +} + +message InitializeResponse {} + +message ShutdownRequest {} + +message ShutdownResponse {} + +message CreateHandlersRequest {} + +message CreateHandlersResponse { + repeated Handler handlers = 1; +} + +message Handler { + string prefix = 1; + uint32 lockOptions = 2; + uint32 server = 3; +} + +message BuildBlockRequest {} + +message BuildBlockResponse { + bytes id = 1; + bytes parentID = 2; + bytes bytes = 3; + // status is always processing +} + +message ParseBlockRequest { + bytes bytes = 1; +} + +message ParseBlockResponse { + bytes id = 1; + bytes parentID = 2; + uint32 status = 3; +} + +message GetBlockRequest { + bytes id = 1; +} + +message GetBlockResponse { + bytes parentID = 1; + bytes bytes = 2; + uint32 status = 3; +} + +message SetPreferenceRequest { + bytes id = 1; +} + +message SetPreferenceResponse {} + +message LastAcceptedRequest {} + +message LastAcceptedResponse { + bytes id = 1; +} + +message BlockVerifyRequest { + bytes id = 1; +} + +message BlockVerifyResponse {} + +message BlockAcceptRequest { + bytes id = 1; +} + +message BlockAcceptResponse {} + +message BlockRejectRequest { + bytes id = 1; +} + +message BlockRejectResponse {} + +service VM { + rpc Initialize(InitializeRequest) returns (InitializeResponse); + rpc Shutdown(ShutdownRequest) returns (ShutdownResponse); + rpc CreateHandlers(CreateHandlersRequest) returns (CreateHandlersResponse); + rpc BuildBlock(BuildBlockRequest) returns (BuildBlockResponse); + rpc ParseBlock(ParseBlockRequest) returns (ParseBlockResponse); + rpc GetBlock(GetBlockRequest) returns (GetBlockResponse); + rpc SetPreference(SetPreferenceRequest) returns (SetPreferenceResponse); + rpc LastAccepted(LastAcceptedRequest) returns (LastAcceptedResponse); + + rpc BlockVerify(BlockVerifyRequest) returns (BlockVerifyResponse); + rpc BlockAccept(BlockAcceptRequest) returns (BlockAcceptResponse); + rpc BlockReject(BlockRejectRequest) returns (BlockRejectResponse); +} \ No newline at end of file diff --git a/vms/rpcchainvm/vm.go b/vms/rpcchainvm/vm.go new file mode 100644 index 0000000..083fbd3 --- /dev/null +++ b/vms/rpcchainvm/vm.go @@ -0,0 +1,50 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package rpcchainvm + +import ( + "golang.org/x/net/context" + + "google.golang.org/grpc" + + "github.com/hashicorp/go-plugin" + + "github.com/ava-labs/gecko/snow/engine/snowman" + "github.com/ava-labs/gecko/vms/rpcchainvm/proto" +) + +// Handshake is a common handshake that is shared by plugin and host. +var Handshake = plugin.HandshakeConfig{ + ProtocolVersion: 1, + MagicCookieKey: "VM_PLUGIN", + MagicCookieValue: "dynamic", +} + +// PluginMap is the map of plugins we can dispense. +var PluginMap = map[string]plugin.Plugin{ + "vm": &Plugin{}, +} + +// Plugin is the implementation of plugin.Plugin so we can serve/consume this. +// We also implement GRPCPlugin so that this plugin can be served over gRPC. +type Plugin struct { + plugin.NetRPCUnsupportedPlugin + // Concrete implementation, written in Go. This is only used for plugins + // that are written in Go. + vm snowman.ChainVM +} + +// New ... +func New(vm snowman.ChainVM) *Plugin { return &Plugin{vm: vm} } + +// GRPCServer ... +func (p *Plugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error { + proto.RegisterVMServer(s, NewServer(p.vm, broker)) + return nil +} + +// GRPCClient ... +func (p *Plugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) { + return NewClient(proto.NewVMClient(c), broker), nil +} diff --git a/vms/rpcchainvm/vm_client.go b/vms/rpcchainvm/vm_client.go new file mode 100644 index 0000000..45b727d --- /dev/null +++ b/vms/rpcchainvm/vm_client.go @@ -0,0 +1,336 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package rpcchainvm + +import ( + "context" + "errors" + "sync" + + "google.golang.org/grpc" + + "github.com/hashicorp/go-plugin" + + "github.com/ava-labs/gecko/database" + "github.com/ava-labs/gecko/database/rpcdb" + "github.com/ava-labs/gecko/ids" + "github.com/ava-labs/gecko/snow" + "github.com/ava-labs/gecko/snow/choices" + "github.com/ava-labs/gecko/snow/consensus/snowman" + "github.com/ava-labs/gecko/snow/engine/common" + "github.com/ava-labs/gecko/vms/components/missing" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp" + "github.com/ava-labs/gecko/vms/rpcchainvm/messenger" + + dbproto "github.com/ava-labs/gecko/database/rpcdb/proto" + httpproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/proto" + msgproto "github.com/ava-labs/gecko/vms/rpcchainvm/messenger/proto" + vmproto "github.com/ava-labs/gecko/vms/rpcchainvm/proto" +) + +var ( + errUnsupportedFXs = errors.New("unsupported feature extensions") +) + +// VMClient is an implementation of VM that talks over RPC. +type VMClient struct { + client vmproto.VMClient + broker *plugin.GRPCBroker + proc *plugin.Client + + db *rpcdb.DatabaseServer + messenger *messenger.Server + + lock sync.Mutex + closed bool + servers []*grpc.Server + conns []*grpc.ClientConn + + ctx *snow.Context + blks map[[32]byte]*BlockClient +} + +// NewClient returns a database instance connected to a remote database instance +func NewClient(client vmproto.VMClient, broker *plugin.GRPCBroker) *VMClient { + return &VMClient{ + client: client, + broker: broker, + } +} + +// SetProcess ... +func (vm *VMClient) SetProcess(proc *plugin.Client) { + vm.proc = proc +} + +// Initialize ... +func (vm *VMClient) Initialize( + ctx *snow.Context, + db database.Database, + genesisBytes []byte, + toEngine chan<- common.Message, + fxs []*common.Fx, +) error { + if len(fxs) != 0 { + return errUnsupportedFXs + } + + vm.ctx = ctx + + vm.db = rpcdb.NewServer(db) + vm.messenger = messenger.NewServer(toEngine) + + // start the db server + dbBrokerID := vm.broker.NextId() + go vm.broker.AcceptAndServe(dbBrokerID, vm.startDBServer) + + // start the messenger server + messengerBrokerID := vm.broker.NextId() + go vm.broker.AcceptAndServe(messengerBrokerID, vm.startMessengerServer) + + _, err := vm.client.Initialize(context.Background(), &vmproto.InitializeRequest{ + DbServer: dbBrokerID, + GenesisBytes: genesisBytes, + EngineServer: messengerBrokerID, + }) + return err +} + +func (vm *VMClient) startDBServer(opts []grpc.ServerOption) *grpc.Server { + vm.lock.Lock() + defer vm.lock.Unlock() + + server := grpc.NewServer(opts...) + + if vm.closed { + server.Stop() + } else { + vm.servers = append(vm.servers, server) + } + + dbproto.RegisterDatabaseServer(server, vm.db) + return server +} + +func (vm *VMClient) startMessengerServer(opts []grpc.ServerOption) *grpc.Server { + vm.lock.Lock() + defer vm.lock.Unlock() + + server := grpc.NewServer(opts...) + + if vm.closed { + server.Stop() + } else { + vm.servers = append(vm.servers, server) + } + + msgproto.RegisterMessengerServer(server, vm.messenger) + return server +} + +// Shutdown ... +func (vm *VMClient) Shutdown() { + vm.lock.Lock() + defer vm.lock.Unlock() + + if vm.closed { + return + } + + vm.closed = true + + vm.client.Shutdown(context.Background(), &vmproto.ShutdownRequest{}) + + for _, server := range vm.servers { + server.Stop() + } + for _, conn := range vm.conns { + conn.Close() + } + + vm.proc.Kill() +} + +// CreateHandlers ... +func (vm *VMClient) CreateHandlers() map[string]*common.HTTPHandler { + vm.lock.Lock() + defer vm.lock.Unlock() + + if vm.closed { + return nil + } + + resp, err := vm.client.CreateHandlers(context.Background(), &vmproto.CreateHandlersRequest{}) + vm.ctx.Log.AssertNoError(err) + + handlers := make(map[string]*common.HTTPHandler, len(resp.Handlers)) + for _, handler := range resp.Handlers { + conn, err := vm.broker.Dial(handler.Server) + vm.ctx.Log.AssertNoError(err) + + vm.conns = append(vm.conns, conn) + handlers[handler.Prefix] = &common.HTTPHandler{ + LockOptions: common.LockOption(handler.LockOptions), + Handler: ghttp.NewClient(httpproto.NewHTTPClient(conn)), + } + } + return handlers +} + +// BuildBlock ... +func (vm *VMClient) BuildBlock() (snowman.Block, error) { + resp, err := vm.client.BuildBlock(context.Background(), &vmproto.BuildBlockRequest{}) + if err != nil { + return nil, err + } + + id, err := ids.ToID(resp.Id) + vm.ctx.Log.AssertNoError(err) + parentID, err := ids.ToID(resp.ParentID) + vm.ctx.Log.AssertNoError(err) + + return &BlockClient{ + vm: vm, + id: id, + parentID: parentID, + status: choices.Processing, + bytes: resp.Bytes, + }, nil +} + +// ParseBlock ... +func (vm *VMClient) ParseBlock(bytes []byte) (snowman.Block, error) { + resp, err := vm.client.ParseBlock(context.Background(), &vmproto.ParseBlockRequest{ + Bytes: bytes, + }) + if err != nil { + return nil, err + } + + id, err := ids.ToID(resp.Id) + vm.ctx.Log.AssertNoError(err) + + if blk, cached := vm.blks[id.Key()]; cached { + return blk, nil + } + + parentID, err := ids.ToID(resp.ParentID) + vm.ctx.Log.AssertNoError(err) + status := choices.Status(resp.Status) + vm.ctx.Log.AssertDeferredNoError(status.Valid) + + return &BlockClient{ + vm: vm, + id: id, + parentID: parentID, + status: status, + bytes: bytes, + }, nil +} + +// GetBlock ... +func (vm *VMClient) GetBlock(id ids.ID) (snowman.Block, error) { + if blk, cached := vm.blks[id.Key()]; cached { + return blk, nil + } + + resp, err := vm.client.GetBlock(context.Background(), &vmproto.GetBlockRequest{ + Id: id.Bytes(), + }) + if err != nil { + return nil, err + } + + parentID, err := ids.ToID(resp.ParentID) + vm.ctx.Log.AssertNoError(err) + status := choices.Status(resp.Status) + vm.ctx.Log.AssertDeferredNoError(status.Valid) + + return &BlockClient{ + vm: vm, + id: id, + parentID: parentID, + status: status, + bytes: resp.Bytes, + }, nil +} + +// SetPreference ... +func (vm *VMClient) SetPreference(id ids.ID) { + _, err := vm.client.SetPreference(context.Background(), &vmproto.SetPreferenceRequest{ + Id: id.Bytes(), + }) + vm.ctx.Log.AssertNoError(err) +} + +// LastAccepted ... +func (vm *VMClient) LastAccepted() ids.ID { + resp, err := vm.client.LastAccepted(context.Background(), &vmproto.LastAcceptedRequest{}) + vm.ctx.Log.AssertNoError(err) + + id, err := ids.ToID(resp.Id) + vm.ctx.Log.AssertNoError(err) + + return id +} + +// BlockClient is an implementation of Block that talks over RPC. +type BlockClient struct { + vm *VMClient + + id ids.ID + parentID ids.ID + status choices.Status + bytes []byte +} + +// ID ... +func (b *BlockClient) ID() ids.ID { return b.id } + +// Accept ... +func (b *BlockClient) Accept() { + delete(b.vm.blks, b.id.Key()) + b.status = choices.Accepted + _, err := b.vm.client.BlockAccept(context.Background(), &vmproto.BlockAcceptRequest{ + Id: b.id.Bytes(), + }) + b.vm.ctx.Log.AssertNoError(err) +} + +// Reject ... +func (b *BlockClient) Reject() { + delete(b.vm.blks, b.id.Key()) + b.status = choices.Rejected + _, err := b.vm.client.BlockReject(context.Background(), &vmproto.BlockRejectRequest{ + Id: b.id.Bytes(), + }) + b.vm.ctx.Log.AssertNoError(err) +} + +// Status ... +func (b *BlockClient) Status() choices.Status { return b.status } + +// Parent ... +func (b *BlockClient) Parent() snowman.Block { + if parent, err := b.vm.GetBlock(b.parentID); err == nil { + return parent + } + return &missing.Block{BlkID: b.parentID} +} + +// Verify ... +func (b *BlockClient) Verify() error { + _, err := b.vm.client.BlockVerify(context.Background(), &vmproto.BlockVerifyRequest{ + Id: b.id.Bytes(), + }) + if err != nil { + return err + } + + b.vm.blks[b.id.Key()] = b + return nil +} + +// Bytes ... +func (b *BlockClient) Bytes() []byte { return b.bytes } diff --git a/vms/rpcchainvm/vm_server.go b/vms/rpcchainvm/vm_server.go new file mode 100644 index 0000000..217a1f2 --- /dev/null +++ b/vms/rpcchainvm/vm_server.go @@ -0,0 +1,240 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package rpcchainvm + +import ( + "context" + "sync" + + "google.golang.org/grpc" + + "github.com/hashicorp/go-plugin" + + "github.com/ava-labs/gecko/database/rpcdb" + "github.com/ava-labs/gecko/ids" + "github.com/ava-labs/gecko/snow" + "github.com/ava-labs/gecko/snow/engine/common" + "github.com/ava-labs/gecko/snow/engine/snowman" + "github.com/ava-labs/gecko/utils/wrappers" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp" + "github.com/ava-labs/gecko/vms/rpcchainvm/messenger" + + dbproto "github.com/ava-labs/gecko/database/rpcdb/proto" + httpproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/proto" + msgproto "github.com/ava-labs/gecko/vms/rpcchainvm/messenger/proto" + vmproto "github.com/ava-labs/gecko/vms/rpcchainvm/proto" +) + +// VMServer is a VM that is managed over RPC. +type VMServer struct { + vm snowman.ChainVM + broker *plugin.GRPCBroker + + lock sync.Mutex + closed bool + servers []*grpc.Server + conns []*grpc.ClientConn + + toEngine chan common.Message +} + +// NewServer returns a vm instance connected to a remote vm instance +func NewServer(vm snowman.ChainVM, broker *plugin.GRPCBroker) *VMServer { + return &VMServer{ + vm: vm, + broker: broker, + } +} + +// Initialize ... +func (vm *VMServer) Initialize(_ context.Context, req *vmproto.InitializeRequest) (*vmproto.InitializeResponse, error) { + dbConn, err := vm.broker.Dial(req.DbServer) + if err != nil { + return nil, err + } + msgConn, err := vm.broker.Dial(req.EngineServer) + if err != nil { + dbConn.Close() + return nil, err + } + + dbClient := rpcdb.NewClient(dbproto.NewDatabaseClient(dbConn)) + msgClient := messenger.NewClient(msgproto.NewMessengerClient(msgConn)) + + toEngine := make(chan common.Message, 1) + go func() { + for msg := range toEngine { + msgClient.Notify(msg) + } + }() + + // TODO: Needs to populate a real context + ctx := snow.DefaultContextTest() + + if err := vm.vm.Initialize(ctx, dbClient, req.GenesisBytes, toEngine, nil); err != nil { + dbConn.Close() + msgConn.Close() + close(toEngine) + return nil, err + } + + vm.conns = append(vm.conns, dbConn) + vm.conns = append(vm.conns, msgConn) + vm.toEngine = toEngine + return &vmproto.InitializeResponse{}, nil +} + +// Shutdown ... +func (vm *VMServer) Shutdown(_ context.Context, _ *vmproto.ShutdownRequest) (*vmproto.ShutdownResponse, error) { + vm.lock.Lock() + defer vm.lock.Unlock() + + if vm.closed || vm.toEngine == nil { + return &vmproto.ShutdownResponse{}, nil + } + + vm.closed = true + + vm.vm.Shutdown() + close(vm.toEngine) + + errs := wrappers.Errs{} + for _, conn := range vm.conns { + errs.Add(conn.Close()) + } + return &vmproto.ShutdownResponse{}, errs.Err +} + +// CreateHandlers ... +func (vm *VMServer) CreateHandlers(_ context.Context, req *vmproto.CreateHandlersRequest) (*vmproto.CreateHandlersResponse, error) { + handlers := vm.vm.CreateHandlers() + resp := &vmproto.CreateHandlersResponse{} + for prefix, h := range handlers { + handler := h + + // start the messenger server + serverID := vm.broker.NextId() + go vm.broker.AcceptAndServe(serverID, func(opts []grpc.ServerOption) *grpc.Server { + vm.lock.Lock() + defer vm.lock.Unlock() + + server := grpc.NewServer(opts...) + + if vm.closed { + server.Stop() + } else { + vm.servers = append(vm.servers, server) + } + + httpproto.RegisterHTTPServer(server, ghttp.NewServer(handler.Handler)) + return server + }) + + resp.Handlers = append(resp.Handlers, &vmproto.Handler{ + Prefix: prefix, + LockOptions: uint32(handler.LockOptions), + Server: serverID, + }) + } + return resp, nil +} + +// BuildBlock ... +func (vm *VMServer) BuildBlock(_ context.Context, _ *vmproto.BuildBlockRequest) (*vmproto.BuildBlockResponse, error) { + blk, err := vm.vm.BuildBlock() + if err != nil { + return nil, err + } + return &vmproto.BuildBlockResponse{ + Id: blk.ID().Bytes(), + ParentID: blk.Parent().ID().Bytes(), + Bytes: blk.Bytes(), + }, nil +} + +// ParseBlock ... +func (vm *VMServer) ParseBlock(_ context.Context, req *vmproto.ParseBlockRequest) (*vmproto.ParseBlockResponse, error) { + blk, err := vm.vm.ParseBlock(req.Bytes) + if err != nil { + return nil, err + } + return &vmproto.ParseBlockResponse{ + Id: blk.ID().Bytes(), + ParentID: blk.Parent().ID().Bytes(), + Status: uint32(blk.Status()), + }, nil +} + +// GetBlock ... +func (vm *VMServer) GetBlock(_ context.Context, req *vmproto.GetBlockRequest) (*vmproto.GetBlockResponse, error) { + id, err := ids.ToID(req.Id) + if err != nil { + return nil, err + } + blk, err := vm.vm.GetBlock(id) + if err != nil { + return nil, err + } + return &vmproto.GetBlockResponse{ + ParentID: blk.Parent().ID().Bytes(), + Bytes: blk.Bytes(), + Status: uint32(blk.Status()), + }, nil +} + +// SetPreference ... +func (vm *VMServer) SetPreference(_ context.Context, req *vmproto.SetPreferenceRequest) (*vmproto.SetPreferenceResponse, error) { + id, err := ids.ToID(req.Id) + if err != nil { + return nil, err + } + vm.vm.SetPreference(id) + return &vmproto.SetPreferenceResponse{}, nil +} + +// LastAccepted ... +func (vm *VMServer) LastAccepted(_ context.Context, _ *vmproto.LastAcceptedRequest) (*vmproto.LastAcceptedResponse, error) { + return &vmproto.LastAcceptedResponse{Id: vm.vm.LastAccepted().Bytes()}, nil +} + +// BlockVerify ... +func (vm *VMServer) BlockVerify(_ context.Context, req *vmproto.BlockVerifyRequest) (*vmproto.BlockVerifyResponse, error) { + id, err := ids.ToID(req.Id) + if err != nil { + return nil, err + } + blk, err := vm.vm.GetBlock(id) + if err != nil { + return nil, err + } + return &vmproto.BlockVerifyResponse{}, blk.Verify() +} + +// BlockAccept ... +func (vm *VMServer) BlockAccept(_ context.Context, req *vmproto.BlockAcceptRequest) (*vmproto.BlockAcceptResponse, error) { + id, err := ids.ToID(req.Id) + if err != nil { + return nil, err + } + blk, err := vm.vm.GetBlock(id) + if err != nil { + return nil, err + } + blk.Accept() + return &vmproto.BlockAcceptResponse{}, nil +} + +// BlockReject ... +func (vm *VMServer) BlockReject(_ context.Context, req *vmproto.BlockRejectRequest) (*vmproto.BlockRejectResponse, error) { + id, err := ids.ToID(req.Id) + if err != nil { + return nil, err + } + blk, err := vm.vm.GetBlock(id) + if err != nil { + return nil, err + } + blk.Reject() + return &vmproto.BlockRejectResponse{}, nil +} diff --git a/vms/secp256k1fx/factory.go b/vms/secp256k1fx/factory.go index da2e022..cdcb200 100644 --- a/vms/secp256k1fx/factory.go +++ b/vms/secp256k1fx/factory.go @@ -16,4 +16,4 @@ var ( type Factory struct{} // New ... -func (f *Factory) New() interface{} { return &Fx{} } +func (f *Factory) New() (interface{}, error) { return &Fx{}, nil } diff --git a/vms/secp256k1fx/factory_test.go b/vms/secp256k1fx/factory_test.go index 54bc901..1c92b6a 100644 --- a/vms/secp256k1fx/factory_test.go +++ b/vms/secp256k1fx/factory_test.go @@ -9,7 +9,9 @@ import ( func TestFactory(t *testing.T) { factory := Factory{} - if fx := factory.New(); fx == nil { + if fx, err := factory.New(); err != nil { + t.Fatal(err) + } else if fx == nil { t.Fatalf("Factory.New returned nil") } } diff --git a/vms/spchainvm/factory.go b/vms/spchainvm/factory.go index 6cb6fe2..0b8fa98 100644 --- a/vms/spchainvm/factory.go +++ b/vms/spchainvm/factory.go @@ -16,4 +16,4 @@ var ( type Factory struct{} // New ... -func (f *Factory) New() interface{} { return &VM{} } +func (f *Factory) New() (interface{}, error) { return &VM{}, nil } diff --git a/vms/spchainvm/vm.go b/vms/spchainvm/vm.go index 6b71ce6..8956097 100644 --- a/vms/spchainvm/vm.go +++ b/vms/spchainvm/vm.go @@ -118,6 +118,10 @@ func (vm *VM) Initialize( // Shutdown implements the snowman.ChainVM interface func (vm *VM) Shutdown() { + if vm.timer == nil { + return + } + vm.timer.Stop() if err := vm.baseDB.Close(); err != nil { vm.ctx.Log.Error("Closing the database failed with %s", err) diff --git a/vms/spdagvm/factory.go b/vms/spdagvm/factory.go index 7e6e263..04e20ab 100644 --- a/vms/spdagvm/factory.go +++ b/vms/spdagvm/factory.go @@ -16,6 +16,6 @@ var ( type Factory struct{ TxFee uint64 } // New ... -func (f *Factory) New() interface{} { - return &VM{TxFee: f.TxFee} // Use the tx fee from the config +func (f *Factory) New() (interface{}, error) { + return &VM{TxFee: f.TxFee}, nil } diff --git a/vms/spdagvm/vm.go b/vms/spdagvm/vm.go index b873185..f23b2ca 100644 --- a/vms/spdagvm/vm.go +++ b/vms/spdagvm/vm.go @@ -130,6 +130,10 @@ func (vm *VM) Initialize( // Shutdown implements the avalanche.DAGVM interface func (vm *VM) Shutdown() { + if vm.timer == nil { + return + } + vm.timer.Stop() if err := vm.baseDB.Close(); err != nil { vm.ctx.Log.Error("Closing the database failed with %s", err) diff --git a/vms/timestampvm/factory.go b/vms/timestampvm/factory.go index 0800395..fb9a9ae 100644 --- a/vms/timestampvm/factory.go +++ b/vms/timestampvm/factory.go @@ -14,4 +14,4 @@ var ( type Factory struct{} // New ... -func (f *Factory) New() interface{} { return &VM{} } +func (f *Factory) New() (interface{}, error) { return &VM{}, nil } From 91f4c85bb2cd145b7ac06a13b40d16afc6991a12 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Thu, 16 Apr 2020 20:26:18 +0100 Subject: [PATCH 14/61] vms: Remove resolved locking TODO The question was answered in https://github.com/ava-labs/gecko/pull/59#discussion_r406597250 > In general, the lock needs to be held whenever a VM function is called > by the consensus engine. Depending on the locking specified in > CreateHandlers locks may be held when an RPC is called as well. > For the AVM specifically, the lock is assumed to be held both when an > RPC is called and when any function is called, except for the ws API. --- vms/avm/service_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index 710974c..dff4c3e 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -45,8 +45,6 @@ func setup(t *testing.T) ([]byte, *VM, *Service) { func TestServiceIssueTx(t *testing.T) { genesisBytes, vm, s := setup(t) - // TODO: Does this need to be here? Or can the lock be released once the - // VM is initilized? defer ctx.Lock.Unlock() defer vm.Shutdown() From 2f0b10530dc67d1a799f30ed7953a2cb3fe3366a Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Fri, 17 Apr 2020 02:03:17 -0400 Subject: [PATCH 15/61] Support websockets over the grpc --- vms/rpcchainvm/ghttp/gconn/conn_client.go | 118 +++ vms/rpcchainvm/ghttp/gconn/conn_server.go | 80 ++ vms/rpcchainvm/ghttp/gconn/proto/conn.pb.go | 788 ++++++++++++++++++ vms/rpcchainvm/ghttp/gconn/proto/conn.proto | 53 ++ .../ghttp/greadcloser/proto/reader.pb.go | 323 +++++++ .../ghttp/greadcloser/proto/reader.proto | 21 + .../ghttp/greadcloser/reader_client.go | 42 + .../ghttp/greadcloser/reader_server.go | 38 + .../ghttp/greader/proto/reader.pb.go | 221 +++++ .../ghttp/greader/proto/reader.proto | 16 + vms/rpcchainvm/ghttp/greader/reader_client.go | 36 + vms/rpcchainvm/ghttp/greader/reader_server.go | 33 + .../ghttp/gresponsewriter/proto/writer.pb.go | 648 ++++++++++++++ .../ghttp/gresponsewriter/proto/writer.proto | 46 + .../ghttp/gresponsewriter/writer_client.go | 134 +++ .../ghttp/gresponsewriter/writer_server.go | 123 +++ .../ghttp/gwriter/proto/writer.pb.go | 221 +++++ .../ghttp/gwriter/proto/writer.proto | 16 + vms/rpcchainvm/ghttp/gwriter/writer_client.go | 34 + vms/rpcchainvm/ghttp/gwriter/writer_server.go | 32 + vms/rpcchainvm/ghttp/http_client.go | 152 +++- vms/rpcchainvm/ghttp/http_server.go | 149 +++- vms/rpcchainvm/ghttp/http_test.go | 96 --- vms/rpcchainvm/ghttp/proto/http.pb.go | 666 +++++++++++++-- vms/rpcchainvm/ghttp/proto/http.proto | 71 +- vms/rpcchainvm/vm_client.go | 2 +- vms/rpcchainvm/vm_server.go | 2 +- 27 files changed, 3898 insertions(+), 263 deletions(-) create mode 100644 vms/rpcchainvm/ghttp/gconn/conn_client.go create mode 100644 vms/rpcchainvm/ghttp/gconn/conn_server.go create mode 100644 vms/rpcchainvm/ghttp/gconn/proto/conn.pb.go create mode 100644 vms/rpcchainvm/ghttp/gconn/proto/conn.proto create mode 100644 vms/rpcchainvm/ghttp/greadcloser/proto/reader.pb.go create mode 100644 vms/rpcchainvm/ghttp/greadcloser/proto/reader.proto create mode 100644 vms/rpcchainvm/ghttp/greadcloser/reader_client.go create mode 100644 vms/rpcchainvm/ghttp/greadcloser/reader_server.go create mode 100644 vms/rpcchainvm/ghttp/greader/proto/reader.pb.go create mode 100644 vms/rpcchainvm/ghttp/greader/proto/reader.proto create mode 100644 vms/rpcchainvm/ghttp/greader/reader_client.go create mode 100644 vms/rpcchainvm/ghttp/greader/reader_server.go create mode 100644 vms/rpcchainvm/ghttp/gresponsewriter/proto/writer.pb.go create mode 100644 vms/rpcchainvm/ghttp/gresponsewriter/proto/writer.proto create mode 100644 vms/rpcchainvm/ghttp/gresponsewriter/writer_client.go create mode 100644 vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go create mode 100644 vms/rpcchainvm/ghttp/gwriter/proto/writer.pb.go create mode 100644 vms/rpcchainvm/ghttp/gwriter/proto/writer.proto create mode 100644 vms/rpcchainvm/ghttp/gwriter/writer_client.go create mode 100644 vms/rpcchainvm/ghttp/gwriter/writer_server.go delete mode 100644 vms/rpcchainvm/ghttp/http_test.go diff --git a/vms/rpcchainvm/ghttp/gconn/conn_client.go b/vms/rpcchainvm/ghttp/gconn/conn_client.go new file mode 100644 index 0000000..d35e1a4 --- /dev/null +++ b/vms/rpcchainvm/ghttp/gconn/conn_client.go @@ -0,0 +1,118 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package gconn + +import ( + "context" + "errors" + "io" + "net" + "time" + + "github.com/ava-labs/gecko/utils/wrappers" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gconn/proto" +) + +// Client is an implementation of a messenger channel that talks over RPC. +type Client struct { + client proto.ConnClient + local net.Addr + remote net.Addr + toClose []io.Closer +} + +// NewClient returns a database instance connected to a remote database instance +func NewClient(client proto.ConnClient, local, remote net.Addr, toClose ...io.Closer) *Client { + return &Client{ + client: client, + local: local, + remote: remote, + toClose: toClose, + } +} + +// Read ... +func (c *Client) Read(p []byte) (int, error) { + resp, err := c.client.Read(context.Background(), &proto.ReadRequest{ + Length: int32(len(p)), + }) + if err != nil { + return 0, err + } + + copy(p, resp.Read) + + if resp.Errored { + err = errors.New(resp.Error) + } + return len(resp.Read), err +} + +// Write ... +func (c *Client) Write(b []byte) (int, error) { + resp, err := c.client.Write(context.Background(), &proto.WriteRequest{ + Payload: b, + }) + if err != nil { + return 0, err + } + + if resp.Errored { + err = errors.New(resp.Error) + } + return int(resp.Length), err +} + +// Close ... +func (c *Client) Close() error { + _, err := c.client.Close(context.Background(), &proto.CloseRequest{}) + errs := wrappers.Errs{} + errs.Add(err) + for _, toClose := range c.toClose { + errs.Add(toClose.Close()) + } + return errs.Err +} + +// LocalAddr ... +func (c *Client) LocalAddr() net.Addr { return c.local } + +// RemoteAddr ... +func (c *Client) RemoteAddr() net.Addr { return c.remote } + +// SetDeadline ... +func (c *Client) SetDeadline(t time.Time) error { + bytes, err := t.MarshalBinary() + if err != nil { + return err + } + _, err = c.client.SetDeadline(context.Background(), &proto.SetDeadlineRequest{ + Time: bytes, + }) + return err +} + +// SetReadDeadline ... +func (c *Client) SetReadDeadline(t time.Time) error { + bytes, err := t.MarshalBinary() + if err != nil { + return err + } + _, err = c.client.SetReadDeadline(context.Background(), &proto.SetReadDeadlineRequest{ + Time: bytes, + }) + return err +} + +// SetWriteDeadline ... +func (c *Client) SetWriteDeadline(t time.Time) error { + bytes, err := t.MarshalBinary() + if err != nil { + return err + } + _, err = c.client.SetWriteDeadline(context.Background(), &proto.SetWriteDeadlineRequest{ + Time: bytes, + }) + return err +} diff --git a/vms/rpcchainvm/ghttp/gconn/conn_server.go b/vms/rpcchainvm/ghttp/gconn/conn_server.go new file mode 100644 index 0000000..287463d --- /dev/null +++ b/vms/rpcchainvm/ghttp/gconn/conn_server.go @@ -0,0 +1,80 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package gconn + +import ( + "context" + "net" + "time" + + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gconn/proto" +) + +// Server is a http.Handler that is managed over RPC. +type Server struct{ conn net.Conn } + +// NewServer returns a http.Handler instance manage remotely +func NewServer(conn net.Conn) *Server { + return &Server{conn: conn} +} + +// Read ... +func (s *Server) Read(ctx context.Context, req *proto.ReadRequest) (*proto.ReadResponse, error) { + buf := make([]byte, int(req.Length)) + n, err := s.conn.Read(buf) + resp := &proto.ReadResponse{ + Read: buf[:n], + } + if err != nil { + resp.Errored = true + resp.Error = err.Error() + } + return resp, nil +} + +// Write ... +func (s *Server) Write(ctx context.Context, req *proto.WriteRequest) (*proto.WriteResponse, error) { + n, err := s.conn.Write(req.Payload) + if err != nil { + return nil, err + } + return &proto.WriteResponse{ + Length: int32(n), + }, nil +} + +// Close ... +func (s *Server) Close(ctx context.Context, req *proto.CloseRequest) (*proto.CloseResponse, error) { + return &proto.CloseResponse{}, s.conn.Close() +} + +// SetDeadline ... +func (s *Server) SetDeadline(ctx context.Context, req *proto.SetDeadlineRequest) (*proto.SetDeadlineResponse, error) { + deadline := time.Time{} + err := deadline.UnmarshalBinary(req.Time) + if err != nil { + return nil, err + } + return &proto.SetDeadlineResponse{}, s.conn.SetDeadline(deadline) +} + +// SetReadDeadline ... +func (s *Server) SetReadDeadline(ctx context.Context, req *proto.SetReadDeadlineRequest) (*proto.SetReadDeadlineResponse, error) { + deadline := time.Time{} + err := deadline.UnmarshalBinary(req.Time) + if err != nil { + return nil, err + } + return &proto.SetReadDeadlineResponse{}, s.conn.SetReadDeadline(deadline) +} + +// SetWriteDeadline ... +func (s *Server) SetWriteDeadline(ctx context.Context, req *proto.SetWriteDeadlineRequest) (*proto.SetWriteDeadlineResponse, error) { + deadline := time.Time{} + err := deadline.UnmarshalBinary(req.Time) + if err != nil { + return nil, err + } + return &proto.SetWriteDeadlineResponse{}, s.conn.SetWriteDeadline(deadline) +} diff --git a/vms/rpcchainvm/ghttp/gconn/proto/conn.pb.go b/vms/rpcchainvm/ghttp/gconn/proto/conn.pb.go new file mode 100644 index 0000000..6a4e46f --- /dev/null +++ b/vms/rpcchainvm/ghttp/gconn/proto/conn.pb.go @@ -0,0 +1,788 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: conn.proto + +package proto + +import ( + context "context" + fmt "fmt" + proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type ReadRequest struct { + Length int32 `protobuf:"varint,1,opt,name=length,proto3" json:"length,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ReadRequest) Reset() { *m = ReadRequest{} } +func (m *ReadRequest) String() string { return proto.CompactTextString(m) } +func (*ReadRequest) ProtoMessage() {} +func (*ReadRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_f401a58c1fc7ceef, []int{0} +} + +func (m *ReadRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ReadRequest.Unmarshal(m, b) +} +func (m *ReadRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ReadRequest.Marshal(b, m, deterministic) +} +func (m *ReadRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ReadRequest.Merge(m, src) +} +func (m *ReadRequest) XXX_Size() int { + return xxx_messageInfo_ReadRequest.Size(m) +} +func (m *ReadRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ReadRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ReadRequest proto.InternalMessageInfo + +func (m *ReadRequest) GetLength() int32 { + if m != nil { + return m.Length + } + return 0 +} + +type ReadResponse struct { + Read []byte `protobuf:"bytes,1,opt,name=read,proto3" json:"read,omitempty"` + Error string `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"` + Errored bool `protobuf:"varint,3,opt,name=errored,proto3" json:"errored,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ReadResponse) Reset() { *m = ReadResponse{} } +func (m *ReadResponse) String() string { return proto.CompactTextString(m) } +func (*ReadResponse) ProtoMessage() {} +func (*ReadResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_f401a58c1fc7ceef, []int{1} +} + +func (m *ReadResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ReadResponse.Unmarshal(m, b) +} +func (m *ReadResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ReadResponse.Marshal(b, m, deterministic) +} +func (m *ReadResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ReadResponse.Merge(m, src) +} +func (m *ReadResponse) XXX_Size() int { + return xxx_messageInfo_ReadResponse.Size(m) +} +func (m *ReadResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ReadResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ReadResponse proto.InternalMessageInfo + +func (m *ReadResponse) GetRead() []byte { + if m != nil { + return m.Read + } + return nil +} + +func (m *ReadResponse) GetError() string { + if m != nil { + return m.Error + } + return "" +} + +func (m *ReadResponse) GetErrored() bool { + if m != nil { + return m.Errored + } + return false +} + +type WriteRequest struct { + Payload []byte `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *WriteRequest) Reset() { *m = WriteRequest{} } +func (m *WriteRequest) String() string { return proto.CompactTextString(m) } +func (*WriteRequest) ProtoMessage() {} +func (*WriteRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_f401a58c1fc7ceef, []int{2} +} + +func (m *WriteRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_WriteRequest.Unmarshal(m, b) +} +func (m *WriteRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_WriteRequest.Marshal(b, m, deterministic) +} +func (m *WriteRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_WriteRequest.Merge(m, src) +} +func (m *WriteRequest) XXX_Size() int { + return xxx_messageInfo_WriteRequest.Size(m) +} +func (m *WriteRequest) XXX_DiscardUnknown() { + xxx_messageInfo_WriteRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_WriteRequest proto.InternalMessageInfo + +func (m *WriteRequest) GetPayload() []byte { + if m != nil { + return m.Payload + } + return nil +} + +type WriteResponse struct { + Length int32 `protobuf:"varint,1,opt,name=length,proto3" json:"length,omitempty"` + Error string `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"` + Errored bool `protobuf:"varint,3,opt,name=errored,proto3" json:"errored,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *WriteResponse) Reset() { *m = WriteResponse{} } +func (m *WriteResponse) String() string { return proto.CompactTextString(m) } +func (*WriteResponse) ProtoMessage() {} +func (*WriteResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_f401a58c1fc7ceef, []int{3} +} + +func (m *WriteResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_WriteResponse.Unmarshal(m, b) +} +func (m *WriteResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_WriteResponse.Marshal(b, m, deterministic) +} +func (m *WriteResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_WriteResponse.Merge(m, src) +} +func (m *WriteResponse) XXX_Size() int { + return xxx_messageInfo_WriteResponse.Size(m) +} +func (m *WriteResponse) XXX_DiscardUnknown() { + xxx_messageInfo_WriteResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_WriteResponse proto.InternalMessageInfo + +func (m *WriteResponse) GetLength() int32 { + if m != nil { + return m.Length + } + return 0 +} + +func (m *WriteResponse) GetError() string { + if m != nil { + return m.Error + } + return "" +} + +func (m *WriteResponse) GetErrored() bool { + if m != nil { + return m.Errored + } + return false +} + +type CloseRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CloseRequest) Reset() { *m = CloseRequest{} } +func (m *CloseRequest) String() string { return proto.CompactTextString(m) } +func (*CloseRequest) ProtoMessage() {} +func (*CloseRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_f401a58c1fc7ceef, []int{4} +} + +func (m *CloseRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CloseRequest.Unmarshal(m, b) +} +func (m *CloseRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CloseRequest.Marshal(b, m, deterministic) +} +func (m *CloseRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_CloseRequest.Merge(m, src) +} +func (m *CloseRequest) XXX_Size() int { + return xxx_messageInfo_CloseRequest.Size(m) +} +func (m *CloseRequest) XXX_DiscardUnknown() { + xxx_messageInfo_CloseRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_CloseRequest proto.InternalMessageInfo + +type CloseResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CloseResponse) Reset() { *m = CloseResponse{} } +func (m *CloseResponse) String() string { return proto.CompactTextString(m) } +func (*CloseResponse) ProtoMessage() {} +func (*CloseResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_f401a58c1fc7ceef, []int{5} +} + +func (m *CloseResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CloseResponse.Unmarshal(m, b) +} +func (m *CloseResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CloseResponse.Marshal(b, m, deterministic) +} +func (m *CloseResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_CloseResponse.Merge(m, src) +} +func (m *CloseResponse) XXX_Size() int { + return xxx_messageInfo_CloseResponse.Size(m) +} +func (m *CloseResponse) XXX_DiscardUnknown() { + xxx_messageInfo_CloseResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_CloseResponse proto.InternalMessageInfo + +type SetDeadlineRequest struct { + Time []byte `protobuf:"bytes,1,opt,name=time,proto3" json:"time,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SetDeadlineRequest) Reset() { *m = SetDeadlineRequest{} } +func (m *SetDeadlineRequest) String() string { return proto.CompactTextString(m) } +func (*SetDeadlineRequest) ProtoMessage() {} +func (*SetDeadlineRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_f401a58c1fc7ceef, []int{6} +} + +func (m *SetDeadlineRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SetDeadlineRequest.Unmarshal(m, b) +} +func (m *SetDeadlineRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SetDeadlineRequest.Marshal(b, m, deterministic) +} +func (m *SetDeadlineRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_SetDeadlineRequest.Merge(m, src) +} +func (m *SetDeadlineRequest) XXX_Size() int { + return xxx_messageInfo_SetDeadlineRequest.Size(m) +} +func (m *SetDeadlineRequest) XXX_DiscardUnknown() { + xxx_messageInfo_SetDeadlineRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_SetDeadlineRequest proto.InternalMessageInfo + +func (m *SetDeadlineRequest) GetTime() []byte { + if m != nil { + return m.Time + } + return nil +} + +type SetDeadlineResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SetDeadlineResponse) Reset() { *m = SetDeadlineResponse{} } +func (m *SetDeadlineResponse) String() string { return proto.CompactTextString(m) } +func (*SetDeadlineResponse) ProtoMessage() {} +func (*SetDeadlineResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_f401a58c1fc7ceef, []int{7} +} + +func (m *SetDeadlineResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SetDeadlineResponse.Unmarshal(m, b) +} +func (m *SetDeadlineResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SetDeadlineResponse.Marshal(b, m, deterministic) +} +func (m *SetDeadlineResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_SetDeadlineResponse.Merge(m, src) +} +func (m *SetDeadlineResponse) XXX_Size() int { + return xxx_messageInfo_SetDeadlineResponse.Size(m) +} +func (m *SetDeadlineResponse) XXX_DiscardUnknown() { + xxx_messageInfo_SetDeadlineResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_SetDeadlineResponse proto.InternalMessageInfo + +type SetReadDeadlineRequest struct { + Time []byte `protobuf:"bytes,1,opt,name=time,proto3" json:"time,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SetReadDeadlineRequest) Reset() { *m = SetReadDeadlineRequest{} } +func (m *SetReadDeadlineRequest) String() string { return proto.CompactTextString(m) } +func (*SetReadDeadlineRequest) ProtoMessage() {} +func (*SetReadDeadlineRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_f401a58c1fc7ceef, []int{8} +} + +func (m *SetReadDeadlineRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SetReadDeadlineRequest.Unmarshal(m, b) +} +func (m *SetReadDeadlineRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SetReadDeadlineRequest.Marshal(b, m, deterministic) +} +func (m *SetReadDeadlineRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_SetReadDeadlineRequest.Merge(m, src) +} +func (m *SetReadDeadlineRequest) XXX_Size() int { + return xxx_messageInfo_SetReadDeadlineRequest.Size(m) +} +func (m *SetReadDeadlineRequest) XXX_DiscardUnknown() { + xxx_messageInfo_SetReadDeadlineRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_SetReadDeadlineRequest proto.InternalMessageInfo + +func (m *SetReadDeadlineRequest) GetTime() []byte { + if m != nil { + return m.Time + } + return nil +} + +type SetReadDeadlineResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SetReadDeadlineResponse) Reset() { *m = SetReadDeadlineResponse{} } +func (m *SetReadDeadlineResponse) String() string { return proto.CompactTextString(m) } +func (*SetReadDeadlineResponse) ProtoMessage() {} +func (*SetReadDeadlineResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_f401a58c1fc7ceef, []int{9} +} + +func (m *SetReadDeadlineResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SetReadDeadlineResponse.Unmarshal(m, b) +} +func (m *SetReadDeadlineResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SetReadDeadlineResponse.Marshal(b, m, deterministic) +} +func (m *SetReadDeadlineResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_SetReadDeadlineResponse.Merge(m, src) +} +func (m *SetReadDeadlineResponse) XXX_Size() int { + return xxx_messageInfo_SetReadDeadlineResponse.Size(m) +} +func (m *SetReadDeadlineResponse) XXX_DiscardUnknown() { + xxx_messageInfo_SetReadDeadlineResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_SetReadDeadlineResponse proto.InternalMessageInfo + +type SetWriteDeadlineRequest struct { + Time []byte `protobuf:"bytes,1,opt,name=time,proto3" json:"time,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SetWriteDeadlineRequest) Reset() { *m = SetWriteDeadlineRequest{} } +func (m *SetWriteDeadlineRequest) String() string { return proto.CompactTextString(m) } +func (*SetWriteDeadlineRequest) ProtoMessage() {} +func (*SetWriteDeadlineRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_f401a58c1fc7ceef, []int{10} +} + +func (m *SetWriteDeadlineRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SetWriteDeadlineRequest.Unmarshal(m, b) +} +func (m *SetWriteDeadlineRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SetWriteDeadlineRequest.Marshal(b, m, deterministic) +} +func (m *SetWriteDeadlineRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_SetWriteDeadlineRequest.Merge(m, src) +} +func (m *SetWriteDeadlineRequest) XXX_Size() int { + return xxx_messageInfo_SetWriteDeadlineRequest.Size(m) +} +func (m *SetWriteDeadlineRequest) XXX_DiscardUnknown() { + xxx_messageInfo_SetWriteDeadlineRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_SetWriteDeadlineRequest proto.InternalMessageInfo + +func (m *SetWriteDeadlineRequest) GetTime() []byte { + if m != nil { + return m.Time + } + return nil +} + +type SetWriteDeadlineResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SetWriteDeadlineResponse) Reset() { *m = SetWriteDeadlineResponse{} } +func (m *SetWriteDeadlineResponse) String() string { return proto.CompactTextString(m) } +func (*SetWriteDeadlineResponse) ProtoMessage() {} +func (*SetWriteDeadlineResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_f401a58c1fc7ceef, []int{11} +} + +func (m *SetWriteDeadlineResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SetWriteDeadlineResponse.Unmarshal(m, b) +} +func (m *SetWriteDeadlineResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SetWriteDeadlineResponse.Marshal(b, m, deterministic) +} +func (m *SetWriteDeadlineResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_SetWriteDeadlineResponse.Merge(m, src) +} +func (m *SetWriteDeadlineResponse) XXX_Size() int { + return xxx_messageInfo_SetWriteDeadlineResponse.Size(m) +} +func (m *SetWriteDeadlineResponse) XXX_DiscardUnknown() { + xxx_messageInfo_SetWriteDeadlineResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_SetWriteDeadlineResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*ReadRequest)(nil), "proto.ReadRequest") + proto.RegisterType((*ReadResponse)(nil), "proto.ReadResponse") + proto.RegisterType((*WriteRequest)(nil), "proto.WriteRequest") + proto.RegisterType((*WriteResponse)(nil), "proto.WriteResponse") + proto.RegisterType((*CloseRequest)(nil), "proto.CloseRequest") + proto.RegisterType((*CloseResponse)(nil), "proto.CloseResponse") + proto.RegisterType((*SetDeadlineRequest)(nil), "proto.SetDeadlineRequest") + proto.RegisterType((*SetDeadlineResponse)(nil), "proto.SetDeadlineResponse") + proto.RegisterType((*SetReadDeadlineRequest)(nil), "proto.SetReadDeadlineRequest") + proto.RegisterType((*SetReadDeadlineResponse)(nil), "proto.SetReadDeadlineResponse") + proto.RegisterType((*SetWriteDeadlineRequest)(nil), "proto.SetWriteDeadlineRequest") + proto.RegisterType((*SetWriteDeadlineResponse)(nil), "proto.SetWriteDeadlineResponse") +} + +func init() { proto.RegisterFile("conn.proto", fileDescriptor_f401a58c1fc7ceef) } + +var fileDescriptor_f401a58c1fc7ceef = []byte{ + // 351 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0xd1, 0x4e, 0xea, 0x40, + 0x10, 0x4d, 0x2f, 0x2d, 0x5c, 0x87, 0x22, 0x66, 0x40, 0x2c, 0x9b, 0xa8, 0x64, 0x13, 0x93, 0x3e, + 0x28, 0x26, 0xf8, 0x09, 0xf0, 0x01, 0x66, 0x79, 0xe0, 0xb9, 0xda, 0x89, 0x92, 0xd4, 0x5d, 0x6c, + 0xd7, 0x07, 0xff, 0xc1, 0x8f, 0x36, 0x6c, 0xb7, 0xa5, 0x05, 0x9a, 0xe0, 0x53, 0xf7, 0xec, 0x39, + 0x73, 0x66, 0x7a, 0x66, 0x01, 0x5e, 0x95, 0x94, 0xd3, 0x4d, 0xaa, 0xb4, 0x42, 0xcf, 0x7c, 0xf8, + 0x1d, 0x74, 0x05, 0x45, 0xb1, 0xa0, 0xcf, 0x2f, 0xca, 0x34, 0x8e, 0xa0, 0x9d, 0x90, 0x7c, 0xd3, + 0xef, 0x81, 0x33, 0x71, 0x42, 0x4f, 0x58, 0xc4, 0x05, 0xf8, 0xb9, 0x2c, 0xdb, 0x28, 0x99, 0x11, + 0x22, 0xb8, 0x29, 0x45, 0xb1, 0x51, 0xf9, 0xc2, 0x9c, 0x71, 0x08, 0x1e, 0xa5, 0xa9, 0x4a, 0x83, + 0x7f, 0x13, 0x27, 0x3c, 0x13, 0x39, 0xc0, 0x00, 0x3a, 0xe6, 0x40, 0x71, 0xd0, 0x9a, 0x38, 0xe1, + 0x7f, 0x51, 0x40, 0x1e, 0x82, 0xbf, 0x4a, 0xd7, 0x9a, 0x8a, 0xde, 0x01, 0x74, 0x36, 0xd1, 0x77, + 0xa2, 0x4a, 0xdb, 0x02, 0xf2, 0x15, 0xf4, 0xac, 0xd2, 0xb6, 0x6f, 0x18, 0xf3, 0xcf, 0x23, 0x9c, + 0x83, 0x3f, 0x4f, 0x54, 0x56, 0x8c, 0xc0, 0xfb, 0xd0, 0xb3, 0x38, 0x6f, 0xc4, 0x43, 0xc0, 0x25, + 0xe9, 0x05, 0x45, 0x71, 0xb2, 0x96, 0xe5, 0xa4, 0x08, 0xae, 0x5e, 0x7f, 0x50, 0xf1, 0xf7, 0xdb, + 0x33, 0xbf, 0x84, 0x41, 0x4d, 0x69, 0x0d, 0xee, 0x61, 0xb4, 0x24, 0xbd, 0xcd, 0xee, 0x14, 0x93, + 0x31, 0x5c, 0x1d, 0xa8, 0xad, 0xd1, 0x83, 0xa1, 0x4c, 0x0c, 0xa7, 0x38, 0x31, 0x08, 0x0e, 0xe5, + 0xb9, 0xd5, 0xec, 0xa7, 0x05, 0xee, 0x5c, 0x49, 0x89, 0x8f, 0xe0, 0x6e, 0x7b, 0x21, 0xe6, 0x6f, + 0x62, 0x5a, 0x79, 0x09, 0x6c, 0x50, 0xbb, 0xb3, 0xb9, 0xcf, 0xc0, 0x33, 0x96, 0x58, 0xb0, 0xd5, + 0x05, 0xb2, 0x61, 0xfd, 0x72, 0x57, 0x63, 0x32, 0x2d, 0x6b, 0xaa, 0x89, 0x97, 0x35, 0xb5, 0xd8, + 0x71, 0x01, 0xdd, 0x4a, 0x98, 0x38, 0xb6, 0xa2, 0xc3, 0x55, 0x30, 0x76, 0x8c, 0xb2, 0x2e, 0xcf, + 0xd0, 0xdf, 0x4b, 0x13, 0xaf, 0x77, 0xf2, 0x23, 0x3b, 0x61, 0x37, 0x4d, 0xb4, 0x75, 0x5c, 0xc2, + 0xc5, 0x7e, 0xaa, 0x58, 0xa9, 0x39, 0xb6, 0x1d, 0x76, 0xdb, 0xc8, 0xe7, 0xa6, 0x2f, 0x6d, 0xc3, + 0x3f, 0xfd, 0x06, 0x00, 0x00, 0xff, 0xff, 0xe3, 0x73, 0x4d, 0x43, 0x9e, 0x03, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConnInterface + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion6 + +// ConnClient is the client API for Conn service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type ConnClient interface { + Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) + Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) + Close(ctx context.Context, in *CloseRequest, opts ...grpc.CallOption) (*CloseResponse, error) + SetDeadline(ctx context.Context, in *SetDeadlineRequest, opts ...grpc.CallOption) (*SetDeadlineResponse, error) + SetReadDeadline(ctx context.Context, in *SetReadDeadlineRequest, opts ...grpc.CallOption) (*SetReadDeadlineResponse, error) + SetWriteDeadline(ctx context.Context, in *SetWriteDeadlineRequest, opts ...grpc.CallOption) (*SetWriteDeadlineResponse, error) +} + +type connClient struct { + cc grpc.ClientConnInterface +} + +func NewConnClient(cc grpc.ClientConnInterface) ConnClient { + return &connClient{cc} +} + +func (c *connClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) { + out := new(ReadResponse) + err := c.cc.Invoke(ctx, "/proto.Conn/Read", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *connClient) Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) { + out := new(WriteResponse) + err := c.cc.Invoke(ctx, "/proto.Conn/Write", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *connClient) Close(ctx context.Context, in *CloseRequest, opts ...grpc.CallOption) (*CloseResponse, error) { + out := new(CloseResponse) + err := c.cc.Invoke(ctx, "/proto.Conn/Close", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *connClient) SetDeadline(ctx context.Context, in *SetDeadlineRequest, opts ...grpc.CallOption) (*SetDeadlineResponse, error) { + out := new(SetDeadlineResponse) + err := c.cc.Invoke(ctx, "/proto.Conn/SetDeadline", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *connClient) SetReadDeadline(ctx context.Context, in *SetReadDeadlineRequest, opts ...grpc.CallOption) (*SetReadDeadlineResponse, error) { + out := new(SetReadDeadlineResponse) + err := c.cc.Invoke(ctx, "/proto.Conn/SetReadDeadline", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *connClient) SetWriteDeadline(ctx context.Context, in *SetWriteDeadlineRequest, opts ...grpc.CallOption) (*SetWriteDeadlineResponse, error) { + out := new(SetWriteDeadlineResponse) + err := c.cc.Invoke(ctx, "/proto.Conn/SetWriteDeadline", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ConnServer is the server API for Conn service. +type ConnServer interface { + Read(context.Context, *ReadRequest) (*ReadResponse, error) + Write(context.Context, *WriteRequest) (*WriteResponse, error) + Close(context.Context, *CloseRequest) (*CloseResponse, error) + SetDeadline(context.Context, *SetDeadlineRequest) (*SetDeadlineResponse, error) + SetReadDeadline(context.Context, *SetReadDeadlineRequest) (*SetReadDeadlineResponse, error) + SetWriteDeadline(context.Context, *SetWriteDeadlineRequest) (*SetWriteDeadlineResponse, error) +} + +// UnimplementedConnServer can be embedded to have forward compatible implementations. +type UnimplementedConnServer struct { +} + +func (*UnimplementedConnServer) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Read not implemented") +} +func (*UnimplementedConnServer) Write(ctx context.Context, req *WriteRequest) (*WriteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Write not implemented") +} +func (*UnimplementedConnServer) Close(ctx context.Context, req *CloseRequest) (*CloseResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Close not implemented") +} +func (*UnimplementedConnServer) SetDeadline(ctx context.Context, req *SetDeadlineRequest) (*SetDeadlineResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SetDeadline not implemented") +} +func (*UnimplementedConnServer) SetReadDeadline(ctx context.Context, req *SetReadDeadlineRequest) (*SetReadDeadlineResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SetReadDeadline not implemented") +} +func (*UnimplementedConnServer) SetWriteDeadline(ctx context.Context, req *SetWriteDeadlineRequest) (*SetWriteDeadlineResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SetWriteDeadline not implemented") +} + +func RegisterConnServer(s *grpc.Server, srv ConnServer) { + s.RegisterService(&_Conn_serviceDesc, srv) +} + +func _Conn_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ReadRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ConnServer).Read(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Conn/Read", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ConnServer).Read(ctx, req.(*ReadRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Conn_Write_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(WriteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ConnServer).Write(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Conn/Write", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ConnServer).Write(ctx, req.(*WriteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Conn_Close_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CloseRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ConnServer).Close(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Conn/Close", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ConnServer).Close(ctx, req.(*CloseRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Conn_SetDeadline_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SetDeadlineRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ConnServer).SetDeadline(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Conn/SetDeadline", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ConnServer).SetDeadline(ctx, req.(*SetDeadlineRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Conn_SetReadDeadline_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SetReadDeadlineRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ConnServer).SetReadDeadline(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Conn/SetReadDeadline", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ConnServer).SetReadDeadline(ctx, req.(*SetReadDeadlineRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Conn_SetWriteDeadline_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SetWriteDeadlineRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ConnServer).SetWriteDeadline(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Conn/SetWriteDeadline", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ConnServer).SetWriteDeadline(ctx, req.(*SetWriteDeadlineRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Conn_serviceDesc = grpc.ServiceDesc{ + ServiceName: "proto.Conn", + HandlerType: (*ConnServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Read", + Handler: _Conn_Read_Handler, + }, + { + MethodName: "Write", + Handler: _Conn_Write_Handler, + }, + { + MethodName: "Close", + Handler: _Conn_Close_Handler, + }, + { + MethodName: "SetDeadline", + Handler: _Conn_SetDeadline_Handler, + }, + { + MethodName: "SetReadDeadline", + Handler: _Conn_SetReadDeadline_Handler, + }, + { + MethodName: "SetWriteDeadline", + Handler: _Conn_SetWriteDeadline_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "conn.proto", +} diff --git a/vms/rpcchainvm/ghttp/gconn/proto/conn.proto b/vms/rpcchainvm/ghttp/gconn/proto/conn.proto new file mode 100644 index 0000000..cc5d150 --- /dev/null +++ b/vms/rpcchainvm/ghttp/gconn/proto/conn.proto @@ -0,0 +1,53 @@ +syntax = "proto3"; +package proto; + +message ReadRequest { + int32 length = 1; +} + +message ReadResponse { + bytes read = 1; + string error = 2; + bool errored = 3; +} + +message WriteRequest { + bytes payload = 1; +} + +message WriteResponse { + int32 length = 1; + string error = 2; + bool errored = 3; +} + +message CloseRequest {} + +message CloseResponse {} + +message SetDeadlineRequest { + bytes time = 1; +} + +message SetDeadlineResponse {} + +message SetReadDeadlineRequest { + bytes time = 1; +} + +message SetReadDeadlineResponse {} + +message SetWriteDeadlineRequest { + bytes time = 1; +} + +message SetWriteDeadlineResponse {} + +service Conn { + rpc Read(ReadRequest) returns (ReadResponse); + rpc Write(WriteRequest) returns (WriteResponse); + rpc Close(CloseRequest) returns (CloseResponse); + rpc SetDeadline(SetDeadlineRequest) returns (SetDeadlineResponse); + rpc SetReadDeadline(SetReadDeadlineRequest) returns (SetReadDeadlineResponse); + rpc SetWriteDeadline(SetWriteDeadlineRequest) returns (SetWriteDeadlineResponse); +} \ No newline at end of file diff --git a/vms/rpcchainvm/ghttp/greadcloser/proto/reader.pb.go b/vms/rpcchainvm/ghttp/greadcloser/proto/reader.pb.go new file mode 100644 index 0000000..682a2e1 --- /dev/null +++ b/vms/rpcchainvm/ghttp/greadcloser/proto/reader.pb.go @@ -0,0 +1,323 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: reader.proto + +package proto + +import ( + context "context" + fmt "fmt" + proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type ReadRequest struct { + Length int32 `protobuf:"varint,1,opt,name=length,proto3" json:"length,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ReadRequest) Reset() { *m = ReadRequest{} } +func (m *ReadRequest) String() string { return proto.CompactTextString(m) } +func (*ReadRequest) ProtoMessage() {} +func (*ReadRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_f534e48276761a43, []int{0} +} + +func (m *ReadRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ReadRequest.Unmarshal(m, b) +} +func (m *ReadRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ReadRequest.Marshal(b, m, deterministic) +} +func (m *ReadRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ReadRequest.Merge(m, src) +} +func (m *ReadRequest) XXX_Size() int { + return xxx_messageInfo_ReadRequest.Size(m) +} +func (m *ReadRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ReadRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ReadRequest proto.InternalMessageInfo + +func (m *ReadRequest) GetLength() int32 { + if m != nil { + return m.Length + } + return 0 +} + +type ReadResponse struct { + Read []byte `protobuf:"bytes,1,opt,name=read,proto3" json:"read,omitempty"` + Error string `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"` + Errored bool `protobuf:"varint,3,opt,name=errored,proto3" json:"errored,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ReadResponse) Reset() { *m = ReadResponse{} } +func (m *ReadResponse) String() string { return proto.CompactTextString(m) } +func (*ReadResponse) ProtoMessage() {} +func (*ReadResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_f534e48276761a43, []int{1} +} + +func (m *ReadResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ReadResponse.Unmarshal(m, b) +} +func (m *ReadResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ReadResponse.Marshal(b, m, deterministic) +} +func (m *ReadResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ReadResponse.Merge(m, src) +} +func (m *ReadResponse) XXX_Size() int { + return xxx_messageInfo_ReadResponse.Size(m) +} +func (m *ReadResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ReadResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ReadResponse proto.InternalMessageInfo + +func (m *ReadResponse) GetRead() []byte { + if m != nil { + return m.Read + } + return nil +} + +func (m *ReadResponse) GetError() string { + if m != nil { + return m.Error + } + return "" +} + +func (m *ReadResponse) GetErrored() bool { + if m != nil { + return m.Errored + } + return false +} + +type CloseRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CloseRequest) Reset() { *m = CloseRequest{} } +func (m *CloseRequest) String() string { return proto.CompactTextString(m) } +func (*CloseRequest) ProtoMessage() {} +func (*CloseRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_f534e48276761a43, []int{2} +} + +func (m *CloseRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CloseRequest.Unmarshal(m, b) +} +func (m *CloseRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CloseRequest.Marshal(b, m, deterministic) +} +func (m *CloseRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_CloseRequest.Merge(m, src) +} +func (m *CloseRequest) XXX_Size() int { + return xxx_messageInfo_CloseRequest.Size(m) +} +func (m *CloseRequest) XXX_DiscardUnknown() { + xxx_messageInfo_CloseRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_CloseRequest proto.InternalMessageInfo + +type CloseResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CloseResponse) Reset() { *m = CloseResponse{} } +func (m *CloseResponse) String() string { return proto.CompactTextString(m) } +func (*CloseResponse) ProtoMessage() {} +func (*CloseResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_f534e48276761a43, []int{3} +} + +func (m *CloseResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CloseResponse.Unmarshal(m, b) +} +func (m *CloseResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CloseResponse.Marshal(b, m, deterministic) +} +func (m *CloseResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_CloseResponse.Merge(m, src) +} +func (m *CloseResponse) XXX_Size() int { + return xxx_messageInfo_CloseResponse.Size(m) +} +func (m *CloseResponse) XXX_DiscardUnknown() { + xxx_messageInfo_CloseResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_CloseResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*ReadRequest)(nil), "proto.ReadRequest") + proto.RegisterType((*ReadResponse)(nil), "proto.ReadResponse") + proto.RegisterType((*CloseRequest)(nil), "proto.CloseRequest") + proto.RegisterType((*CloseResponse)(nil), "proto.CloseResponse") +} + +func init() { proto.RegisterFile("reader.proto", fileDescriptor_f534e48276761a43) } + +var fileDescriptor_f534e48276761a43 = []byte{ + // 195 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x8e, 0xd1, 0x6a, 0x84, 0x30, + 0x10, 0x45, 0x49, 0x6b, 0x6c, 0x3b, 0x4d, 0x5b, 0x98, 0x4a, 0x09, 0x3e, 0x49, 0xa0, 0xe0, 0x93, + 0x0b, 0xee, 0x27, 0xec, 0x1f, 0xcc, 0x1f, 0xb8, 0x38, 0xec, 0x3e, 0xb8, 0xc6, 0x4d, 0xdc, 0xff, + 0x5f, 0x4c, 0x22, 0xe8, 0x53, 0xee, 0xbd, 0x99, 0x99, 0x7b, 0x40, 0x39, 0xee, 0x7a, 0x76, 0xcd, + 0xe4, 0xec, 0x6c, 0x51, 0x86, 0xc7, 0xfc, 0xc3, 0x27, 0x71, 0xd7, 0x13, 0xdf, 0x1f, 0xec, 0x67, + 0xfc, 0x83, 0x7c, 0xe0, 0xf1, 0x32, 0x5f, 0xb5, 0xa8, 0x44, 0x2d, 0x29, 0x39, 0x43, 0xa0, 0xe2, + 0x98, 0x9f, 0xec, 0xe8, 0x19, 0x11, 0xb2, 0xe5, 0x5a, 0x98, 0x52, 0x14, 0x34, 0x16, 0x20, 0xd9, + 0x39, 0xeb, 0xf4, 0x4b, 0x25, 0xea, 0x0f, 0x8a, 0x06, 0x35, 0xbc, 0x05, 0xc1, 0xbd, 0x7e, 0xad, + 0x44, 0xfd, 0x4e, 0xab, 0x35, 0xdf, 0xa0, 0x4e, 0x83, 0xf5, 0x9c, 0xba, 0xcd, 0x0f, 0x7c, 0x25, + 0x1f, 0x4b, 0xda, 0x1b, 0xe4, 0x14, 0x90, 0xf1, 0x00, 0xd9, 0xa2, 0x10, 0x23, 0x7c, 0xb3, 0x41, + 0x2e, 0x7f, 0x77, 0x59, 0xe2, 0x6b, 0x41, 0x86, 0x5b, 0xb8, 0xfe, 0x6e, 0x9b, 0xca, 0x62, 0x1f, + 0xc6, 0x9d, 0x73, 0x1e, 0xc2, 0xe3, 0x33, 0x00, 0x00, 0xff, 0xff, 0x47, 0x74, 0x81, 0x61, 0x28, + 0x01, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConnInterface + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion6 + +// ReaderClient is the client API for Reader service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type ReaderClient interface { + Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) + Close(ctx context.Context, in *CloseRequest, opts ...grpc.CallOption) (*CloseResponse, error) +} + +type readerClient struct { + cc grpc.ClientConnInterface +} + +func NewReaderClient(cc grpc.ClientConnInterface) ReaderClient { + return &readerClient{cc} +} + +func (c *readerClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) { + out := new(ReadResponse) + err := c.cc.Invoke(ctx, "/proto.Reader/Read", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *readerClient) Close(ctx context.Context, in *CloseRequest, opts ...grpc.CallOption) (*CloseResponse, error) { + out := new(CloseResponse) + err := c.cc.Invoke(ctx, "/proto.Reader/Close", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ReaderServer is the server API for Reader service. +type ReaderServer interface { + Read(context.Context, *ReadRequest) (*ReadResponse, error) + Close(context.Context, *CloseRequest) (*CloseResponse, error) +} + +// UnimplementedReaderServer can be embedded to have forward compatible implementations. +type UnimplementedReaderServer struct { +} + +func (*UnimplementedReaderServer) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Read not implemented") +} +func (*UnimplementedReaderServer) Close(ctx context.Context, req *CloseRequest) (*CloseResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Close not implemented") +} + +func RegisterReaderServer(s *grpc.Server, srv ReaderServer) { + s.RegisterService(&_Reader_serviceDesc, srv) +} + +func _Reader_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ReadRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ReaderServer).Read(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Reader/Read", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ReaderServer).Read(ctx, req.(*ReadRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Reader_Close_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CloseRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ReaderServer).Close(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Reader/Close", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ReaderServer).Close(ctx, req.(*CloseRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Reader_serviceDesc = grpc.ServiceDesc{ + ServiceName: "proto.Reader", + HandlerType: (*ReaderServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Read", + Handler: _Reader_Read_Handler, + }, + { + MethodName: "Close", + Handler: _Reader_Close_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "reader.proto", +} diff --git a/vms/rpcchainvm/ghttp/greadcloser/proto/reader.proto b/vms/rpcchainvm/ghttp/greadcloser/proto/reader.proto new file mode 100644 index 0000000..0b300b3 --- /dev/null +++ b/vms/rpcchainvm/ghttp/greadcloser/proto/reader.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; +package proto; + +message ReadRequest { + int32 length = 1; +} + +message ReadResponse { + bytes read = 1; + string error = 2; + bool errored = 3; +} + +message CloseRequest {} + +message CloseResponse {} + +service Reader { + rpc Read(ReadRequest) returns (ReadResponse); + rpc Close(CloseRequest) returns (CloseResponse); +} \ No newline at end of file diff --git a/vms/rpcchainvm/ghttp/greadcloser/reader_client.go b/vms/rpcchainvm/ghttp/greadcloser/reader_client.go new file mode 100644 index 0000000..d5d139e --- /dev/null +++ b/vms/rpcchainvm/ghttp/greadcloser/reader_client.go @@ -0,0 +1,42 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package greadcloser + +import ( + "context" + "errors" + + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greadcloser/proto" +) + +// Client is an implementation of a messenger channel that talks over RPC. +type Client struct{ client proto.ReaderClient } + +// NewClient returns a database instance connected to a remote database instance +func NewClient(client proto.ReaderClient) *Client { + return &Client{client: client} +} + +// Read ... +func (c *Client) Read(p []byte) (int, error) { + resp, err := c.client.Read(context.Background(), &proto.ReadRequest{ + Length: int32(len(p)), + }) + if err != nil { + return 0, err + } + + copy(p, resp.Read) + + if resp.Errored { + err = errors.New(resp.Error) + } + return len(resp.Read), err +} + +// Close ... +func (c *Client) Close() error { + _, err := c.client.Close(context.Background(), &proto.CloseRequest{}) + return err +} diff --git a/vms/rpcchainvm/ghttp/greadcloser/reader_server.go b/vms/rpcchainvm/ghttp/greadcloser/reader_server.go new file mode 100644 index 0000000..5dd7602 --- /dev/null +++ b/vms/rpcchainvm/ghttp/greadcloser/reader_server.go @@ -0,0 +1,38 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package greadcloser + +import ( + "context" + "io" + + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greadcloser/proto" +) + +// Server is a http.Handler that is managed over RPC. +type Server struct{ readCloser io.ReadCloser } + +// NewServer returns a http.Handler instance manage remotely +func NewServer(readCloser io.ReadCloser) *Server { + return &Server{readCloser: readCloser} +} + +// Read ... +func (s *Server) Read(ctx context.Context, req *proto.ReadRequest) (*proto.ReadResponse, error) { + buf := make([]byte, int(req.Length)) + n, err := s.readCloser.Read(buf) + resp := &proto.ReadResponse{ + Read: buf[:n], + } + if err != nil { + resp.Errored = true + resp.Error = err.Error() + } + return resp, nil +} + +// Close ... +func (s *Server) Close(ctx context.Context, req *proto.CloseRequest) (*proto.CloseResponse, error) { + return &proto.CloseResponse{}, s.readCloser.Close() +} diff --git a/vms/rpcchainvm/ghttp/greader/proto/reader.pb.go b/vms/rpcchainvm/ghttp/greader/proto/reader.pb.go new file mode 100644 index 0000000..5bdefa0 --- /dev/null +++ b/vms/rpcchainvm/ghttp/greader/proto/reader.pb.go @@ -0,0 +1,221 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: reader.proto + +package proto + +import ( + context "context" + fmt "fmt" + proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type ReadRequest struct { + Length int32 `protobuf:"varint,1,opt,name=length,proto3" json:"length,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ReadRequest) Reset() { *m = ReadRequest{} } +func (m *ReadRequest) String() string { return proto.CompactTextString(m) } +func (*ReadRequest) ProtoMessage() {} +func (*ReadRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_f534e48276761a43, []int{0} +} + +func (m *ReadRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ReadRequest.Unmarshal(m, b) +} +func (m *ReadRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ReadRequest.Marshal(b, m, deterministic) +} +func (m *ReadRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ReadRequest.Merge(m, src) +} +func (m *ReadRequest) XXX_Size() int { + return xxx_messageInfo_ReadRequest.Size(m) +} +func (m *ReadRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ReadRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ReadRequest proto.InternalMessageInfo + +func (m *ReadRequest) GetLength() int32 { + if m != nil { + return m.Length + } + return 0 +} + +type ReadResponse struct { + Read []byte `protobuf:"bytes,1,opt,name=read,proto3" json:"read,omitempty"` + Error string `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"` + Errored bool `protobuf:"varint,3,opt,name=errored,proto3" json:"errored,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ReadResponse) Reset() { *m = ReadResponse{} } +func (m *ReadResponse) String() string { return proto.CompactTextString(m) } +func (*ReadResponse) ProtoMessage() {} +func (*ReadResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_f534e48276761a43, []int{1} +} + +func (m *ReadResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ReadResponse.Unmarshal(m, b) +} +func (m *ReadResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ReadResponse.Marshal(b, m, deterministic) +} +func (m *ReadResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ReadResponse.Merge(m, src) +} +func (m *ReadResponse) XXX_Size() int { + return xxx_messageInfo_ReadResponse.Size(m) +} +func (m *ReadResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ReadResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ReadResponse proto.InternalMessageInfo + +func (m *ReadResponse) GetRead() []byte { + if m != nil { + return m.Read + } + return nil +} + +func (m *ReadResponse) GetError() string { + if m != nil { + return m.Error + } + return "" +} + +func (m *ReadResponse) GetErrored() bool { + if m != nil { + return m.Errored + } + return false +} + +func init() { + proto.RegisterType((*ReadRequest)(nil), "proto.ReadRequest") + proto.RegisterType((*ReadResponse)(nil), "proto.ReadResponse") +} + +func init() { proto.RegisterFile("reader.proto", fileDescriptor_f534e48276761a43) } + +var fileDescriptor_f534e48276761a43 = []byte{ + // 162 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x8e, 0x41, 0x0a, 0xc2, 0x30, + 0x10, 0x45, 0x89, 0xb6, 0x55, 0xc7, 0xae, 0x46, 0x91, 0xe0, 0xaa, 0x14, 0x84, 0xac, 0x2a, 0xe8, + 0xca, 0x6b, 0xcc, 0x0d, 0x2a, 0x19, 0x74, 0x21, 0x4d, 0x9d, 0xc4, 0xfb, 0x4b, 0x27, 0x0a, 0xba, + 0xca, 0x7f, 0x9f, 0x4f, 0xe6, 0x41, 0x2d, 0xdc, 0x7b, 0x96, 0x6e, 0x94, 0x90, 0x02, 0x96, 0xfa, + 0xb4, 0x07, 0x58, 0x13, 0xf7, 0x9e, 0xf8, 0xf9, 0xe2, 0x98, 0x70, 0x07, 0xd5, 0x83, 0x87, 0x5b, + 0xba, 0x5b, 0xd3, 0x18, 0x57, 0xd2, 0x87, 0x5a, 0x82, 0x3a, 0xcf, 0xe2, 0x18, 0x86, 0xc8, 0x88, + 0x50, 0x4c, 0xbf, 0xe9, 0xaa, 0x26, 0xcd, 0xb8, 0x85, 0x92, 0x45, 0x82, 0xd8, 0x59, 0x63, 0xdc, + 0x8a, 0x32, 0xa0, 0x85, 0x85, 0x06, 0xf6, 0x76, 0xde, 0x18, 0xb7, 0xa4, 0x2f, 0x9e, 0x2e, 0x50, + 0x91, 0x1a, 0xe1, 0x11, 0x8a, 0x29, 0x21, 0x66, 0xb7, 0xee, 0xc7, 0x68, 0xbf, 0xf9, 0xeb, 0xf2, + 0xf9, 0x6b, 0xa5, 0xdd, 0xf9, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x06, 0x11, 0x6f, 0x5d, 0xd3, 0x00, + 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConnInterface + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion6 + +// ReaderClient is the client API for Reader service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type ReaderClient interface { + Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) +} + +type readerClient struct { + cc grpc.ClientConnInterface +} + +func NewReaderClient(cc grpc.ClientConnInterface) ReaderClient { + return &readerClient{cc} +} + +func (c *readerClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) { + out := new(ReadResponse) + err := c.cc.Invoke(ctx, "/proto.Reader/Read", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ReaderServer is the server API for Reader service. +type ReaderServer interface { + Read(context.Context, *ReadRequest) (*ReadResponse, error) +} + +// UnimplementedReaderServer can be embedded to have forward compatible implementations. +type UnimplementedReaderServer struct { +} + +func (*UnimplementedReaderServer) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Read not implemented") +} + +func RegisterReaderServer(s *grpc.Server, srv ReaderServer) { + s.RegisterService(&_Reader_serviceDesc, srv) +} + +func _Reader_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ReadRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ReaderServer).Read(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Reader/Read", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ReaderServer).Read(ctx, req.(*ReadRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Reader_serviceDesc = grpc.ServiceDesc{ + ServiceName: "proto.Reader", + HandlerType: (*ReaderServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Read", + Handler: _Reader_Read_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "reader.proto", +} diff --git a/vms/rpcchainvm/ghttp/greader/proto/reader.proto b/vms/rpcchainvm/ghttp/greader/proto/reader.proto new file mode 100644 index 0000000..80142d3 --- /dev/null +++ b/vms/rpcchainvm/ghttp/greader/proto/reader.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; +package proto; + +message ReadRequest { + int32 length = 1; +} + +message ReadResponse { + bytes read = 1; + string error = 2; + bool errored = 3; +} + +service Reader { + rpc Read(ReadRequest) returns (ReadResponse); +} \ No newline at end of file diff --git a/vms/rpcchainvm/ghttp/greader/reader_client.go b/vms/rpcchainvm/ghttp/greader/reader_client.go new file mode 100644 index 0000000..0505d71 --- /dev/null +++ b/vms/rpcchainvm/ghttp/greader/reader_client.go @@ -0,0 +1,36 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package greader + +import ( + "context" + "errors" + + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greader/proto" +) + +// Client is an implementation of a messenger channel that talks over RPC. +type Client struct{ client proto.ReaderClient } + +// NewClient returns a database instance connected to a remote database instance +func NewClient(client proto.ReaderClient) *Client { + return &Client{client: client} +} + +// Read ... +func (c *Client) Read(p []byte) (int, error) { + resp, err := c.client.Read(context.Background(), &proto.ReadRequest{ + Length: int32(len(p)), + }) + if err != nil { + return 0, err + } + + copy(p, resp.Read) + + if resp.Errored { + err = errors.New(resp.Error) + } + return len(resp.Read), err +} diff --git a/vms/rpcchainvm/ghttp/greader/reader_server.go b/vms/rpcchainvm/ghttp/greader/reader_server.go new file mode 100644 index 0000000..840bd66 --- /dev/null +++ b/vms/rpcchainvm/ghttp/greader/reader_server.go @@ -0,0 +1,33 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package greader + +import ( + "context" + "io" + + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greader/proto" +) + +// Server is a http.Handler that is managed over RPC. +type Server struct{ reader io.Reader } + +// NewServer returns a http.Handler instance manage remotely +func NewServer(reader io.Reader) *Server { + return &Server{reader: reader} +} + +// Read ... +func (s *Server) Read(ctx context.Context, req *proto.ReadRequest) (*proto.ReadResponse, error) { + buf := make([]byte, int(req.Length)) + n, err := s.reader.Read(buf) + resp := &proto.ReadResponse{ + Read: buf[:n], + } + if err != nil { + resp.Errored = true + resp.Error = err.Error() + } + return resp, nil +} diff --git a/vms/rpcchainvm/ghttp/gresponsewriter/proto/writer.pb.go b/vms/rpcchainvm/ghttp/gresponsewriter/proto/writer.pb.go new file mode 100644 index 0000000..a392667 --- /dev/null +++ b/vms/rpcchainvm/ghttp/gresponsewriter/proto/writer.pb.go @@ -0,0 +1,648 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: writer.proto + +package proto + +import ( + context "context" + fmt "fmt" + proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type Header struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Values []string `protobuf:"bytes,2,rep,name=values,proto3" json:"values,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Header) Reset() { *m = Header{} } +func (m *Header) String() string { return proto.CompactTextString(m) } +func (*Header) ProtoMessage() {} +func (*Header) Descriptor() ([]byte, []int) { + return fileDescriptor_ea6fbe89c42e6759, []int{0} +} + +func (m *Header) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Header.Unmarshal(m, b) +} +func (m *Header) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Header.Marshal(b, m, deterministic) +} +func (m *Header) XXX_Merge(src proto.Message) { + xxx_messageInfo_Header.Merge(m, src) +} +func (m *Header) XXX_Size() int { + return xxx_messageInfo_Header.Size(m) +} +func (m *Header) XXX_DiscardUnknown() { + xxx_messageInfo_Header.DiscardUnknown(m) +} + +var xxx_messageInfo_Header proto.InternalMessageInfo + +func (m *Header) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *Header) GetValues() []string { + if m != nil { + return m.Values + } + return nil +} + +type WriteRequest struct { + Headers []*Header `protobuf:"bytes,1,rep,name=headers,proto3" json:"headers,omitempty"` + Payload []byte `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *WriteRequest) Reset() { *m = WriteRequest{} } +func (m *WriteRequest) String() string { return proto.CompactTextString(m) } +func (*WriteRequest) ProtoMessage() {} +func (*WriteRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ea6fbe89c42e6759, []int{1} +} + +func (m *WriteRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_WriteRequest.Unmarshal(m, b) +} +func (m *WriteRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_WriteRequest.Marshal(b, m, deterministic) +} +func (m *WriteRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_WriteRequest.Merge(m, src) +} +func (m *WriteRequest) XXX_Size() int { + return xxx_messageInfo_WriteRequest.Size(m) +} +func (m *WriteRequest) XXX_DiscardUnknown() { + xxx_messageInfo_WriteRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_WriteRequest proto.InternalMessageInfo + +func (m *WriteRequest) GetHeaders() []*Header { + if m != nil { + return m.Headers + } + return nil +} + +func (m *WriteRequest) GetPayload() []byte { + if m != nil { + return m.Payload + } + return nil +} + +type WriteResponse struct { + Written int32 `protobuf:"varint,1,opt,name=written,proto3" json:"written,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *WriteResponse) Reset() { *m = WriteResponse{} } +func (m *WriteResponse) String() string { return proto.CompactTextString(m) } +func (*WriteResponse) ProtoMessage() {} +func (*WriteResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ea6fbe89c42e6759, []int{2} +} + +func (m *WriteResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_WriteResponse.Unmarshal(m, b) +} +func (m *WriteResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_WriteResponse.Marshal(b, m, deterministic) +} +func (m *WriteResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_WriteResponse.Merge(m, src) +} +func (m *WriteResponse) XXX_Size() int { + return xxx_messageInfo_WriteResponse.Size(m) +} +func (m *WriteResponse) XXX_DiscardUnknown() { + xxx_messageInfo_WriteResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_WriteResponse proto.InternalMessageInfo + +func (m *WriteResponse) GetWritten() int32 { + if m != nil { + return m.Written + } + return 0 +} + +type WriteHeaderRequest struct { + Headers []*Header `protobuf:"bytes,1,rep,name=headers,proto3" json:"headers,omitempty"` + StatusCode int32 `protobuf:"varint,2,opt,name=statusCode,proto3" json:"statusCode,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *WriteHeaderRequest) Reset() { *m = WriteHeaderRequest{} } +func (m *WriteHeaderRequest) String() string { return proto.CompactTextString(m) } +func (*WriteHeaderRequest) ProtoMessage() {} +func (*WriteHeaderRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ea6fbe89c42e6759, []int{3} +} + +func (m *WriteHeaderRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_WriteHeaderRequest.Unmarshal(m, b) +} +func (m *WriteHeaderRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_WriteHeaderRequest.Marshal(b, m, deterministic) +} +func (m *WriteHeaderRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_WriteHeaderRequest.Merge(m, src) +} +func (m *WriteHeaderRequest) XXX_Size() int { + return xxx_messageInfo_WriteHeaderRequest.Size(m) +} +func (m *WriteHeaderRequest) XXX_DiscardUnknown() { + xxx_messageInfo_WriteHeaderRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_WriteHeaderRequest proto.InternalMessageInfo + +func (m *WriteHeaderRequest) GetHeaders() []*Header { + if m != nil { + return m.Headers + } + return nil +} + +func (m *WriteHeaderRequest) GetStatusCode() int32 { + if m != nil { + return m.StatusCode + } + return 0 +} + +type WriteHeaderResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *WriteHeaderResponse) Reset() { *m = WriteHeaderResponse{} } +func (m *WriteHeaderResponse) String() string { return proto.CompactTextString(m) } +func (*WriteHeaderResponse) ProtoMessage() {} +func (*WriteHeaderResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ea6fbe89c42e6759, []int{4} +} + +func (m *WriteHeaderResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_WriteHeaderResponse.Unmarshal(m, b) +} +func (m *WriteHeaderResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_WriteHeaderResponse.Marshal(b, m, deterministic) +} +func (m *WriteHeaderResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_WriteHeaderResponse.Merge(m, src) +} +func (m *WriteHeaderResponse) XXX_Size() int { + return xxx_messageInfo_WriteHeaderResponse.Size(m) +} +func (m *WriteHeaderResponse) XXX_DiscardUnknown() { + xxx_messageInfo_WriteHeaderResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_WriteHeaderResponse proto.InternalMessageInfo + +type FlushRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *FlushRequest) Reset() { *m = FlushRequest{} } +func (m *FlushRequest) String() string { return proto.CompactTextString(m) } +func (*FlushRequest) ProtoMessage() {} +func (*FlushRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ea6fbe89c42e6759, []int{5} +} + +func (m *FlushRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_FlushRequest.Unmarshal(m, b) +} +func (m *FlushRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_FlushRequest.Marshal(b, m, deterministic) +} +func (m *FlushRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_FlushRequest.Merge(m, src) +} +func (m *FlushRequest) XXX_Size() int { + return xxx_messageInfo_FlushRequest.Size(m) +} +func (m *FlushRequest) XXX_DiscardUnknown() { + xxx_messageInfo_FlushRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_FlushRequest proto.InternalMessageInfo + +type FlushResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *FlushResponse) Reset() { *m = FlushResponse{} } +func (m *FlushResponse) String() string { return proto.CompactTextString(m) } +func (*FlushResponse) ProtoMessage() {} +func (*FlushResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ea6fbe89c42e6759, []int{6} +} + +func (m *FlushResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_FlushResponse.Unmarshal(m, b) +} +func (m *FlushResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_FlushResponse.Marshal(b, m, deterministic) +} +func (m *FlushResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_FlushResponse.Merge(m, src) +} +func (m *FlushResponse) XXX_Size() int { + return xxx_messageInfo_FlushResponse.Size(m) +} +func (m *FlushResponse) XXX_DiscardUnknown() { + xxx_messageInfo_FlushResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_FlushResponse proto.InternalMessageInfo + +type HijackRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *HijackRequest) Reset() { *m = HijackRequest{} } +func (m *HijackRequest) String() string { return proto.CompactTextString(m) } +func (*HijackRequest) ProtoMessage() {} +func (*HijackRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ea6fbe89c42e6759, []int{7} +} + +func (m *HijackRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_HijackRequest.Unmarshal(m, b) +} +func (m *HijackRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_HijackRequest.Marshal(b, m, deterministic) +} +func (m *HijackRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_HijackRequest.Merge(m, src) +} +func (m *HijackRequest) XXX_Size() int { + return xxx_messageInfo_HijackRequest.Size(m) +} +func (m *HijackRequest) XXX_DiscardUnknown() { + xxx_messageInfo_HijackRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_HijackRequest proto.InternalMessageInfo + +type HijackResponse struct { + ConnServer uint32 `protobuf:"varint,1,opt,name=connServer,proto3" json:"connServer,omitempty"` + LocalNetwork string `protobuf:"bytes,2,opt,name=localNetwork,proto3" json:"localNetwork,omitempty"` + LocalString string `protobuf:"bytes,3,opt,name=localString,proto3" json:"localString,omitempty"` + RemoteNetwork string `protobuf:"bytes,4,opt,name=remoteNetwork,proto3" json:"remoteNetwork,omitempty"` + RemoteString string `protobuf:"bytes,5,opt,name=remoteString,proto3" json:"remoteString,omitempty"` + ReaderServer uint32 `protobuf:"varint,6,opt,name=readerServer,proto3" json:"readerServer,omitempty"` + WriterServer uint32 `protobuf:"varint,7,opt,name=writerServer,proto3" json:"writerServer,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *HijackResponse) Reset() { *m = HijackResponse{} } +func (m *HijackResponse) String() string { return proto.CompactTextString(m) } +func (*HijackResponse) ProtoMessage() {} +func (*HijackResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ea6fbe89c42e6759, []int{8} +} + +func (m *HijackResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_HijackResponse.Unmarshal(m, b) +} +func (m *HijackResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_HijackResponse.Marshal(b, m, deterministic) +} +func (m *HijackResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_HijackResponse.Merge(m, src) +} +func (m *HijackResponse) XXX_Size() int { + return xxx_messageInfo_HijackResponse.Size(m) +} +func (m *HijackResponse) XXX_DiscardUnknown() { + xxx_messageInfo_HijackResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_HijackResponse proto.InternalMessageInfo + +func (m *HijackResponse) GetConnServer() uint32 { + if m != nil { + return m.ConnServer + } + return 0 +} + +func (m *HijackResponse) GetLocalNetwork() string { + if m != nil { + return m.LocalNetwork + } + return "" +} + +func (m *HijackResponse) GetLocalString() string { + if m != nil { + return m.LocalString + } + return "" +} + +func (m *HijackResponse) GetRemoteNetwork() string { + if m != nil { + return m.RemoteNetwork + } + return "" +} + +func (m *HijackResponse) GetRemoteString() string { + if m != nil { + return m.RemoteString + } + return "" +} + +func (m *HijackResponse) GetReaderServer() uint32 { + if m != nil { + return m.ReaderServer + } + return 0 +} + +func (m *HijackResponse) GetWriterServer() uint32 { + if m != nil { + return m.WriterServer + } + return 0 +} + +func init() { + proto.RegisterType((*Header)(nil), "proto.Header") + proto.RegisterType((*WriteRequest)(nil), "proto.WriteRequest") + proto.RegisterType((*WriteResponse)(nil), "proto.WriteResponse") + proto.RegisterType((*WriteHeaderRequest)(nil), "proto.WriteHeaderRequest") + proto.RegisterType((*WriteHeaderResponse)(nil), "proto.WriteHeaderResponse") + proto.RegisterType((*FlushRequest)(nil), "proto.FlushRequest") + proto.RegisterType((*FlushResponse)(nil), "proto.FlushResponse") + proto.RegisterType((*HijackRequest)(nil), "proto.HijackRequest") + proto.RegisterType((*HijackResponse)(nil), "proto.HijackResponse") +} + +func init() { proto.RegisterFile("writer.proto", fileDescriptor_ea6fbe89c42e6759) } + +var fileDescriptor_ea6fbe89c42e6759 = []byte{ + // 408 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0x41, 0x6e, 0xe2, 0x30, + 0x14, 0x86, 0x15, 0x32, 0x09, 0xe2, 0x91, 0xc0, 0xc8, 0x0c, 0xa3, 0x4c, 0x16, 0x28, 0xb2, 0x46, + 0x9a, 0xcc, 0x86, 0x45, 0xaa, 0x9e, 0xa0, 0x55, 0xc5, 0xaa, 0x52, 0xcd, 0xa2, 0xab, 0x2e, 0x52, + 0xb0, 0x0a, 0x25, 0x8d, 0xa9, 0xed, 0x80, 0xb8, 0x41, 0x2f, 0xdb, 0x3b, 0x54, 0xb1, 0x1d, 0x64, + 0x57, 0xdd, 0x74, 0x15, 0xbf, 0xcf, 0x7f, 0xfe, 0xf7, 0xdb, 0xcf, 0x10, 0x1d, 0xf9, 0x56, 0x52, + 0x3e, 0xdf, 0x73, 0x26, 0x19, 0x0a, 0xd4, 0x07, 0x17, 0x10, 0x2e, 0x68, 0xb9, 0xa6, 0x1c, 0xfd, + 0x04, 0x7f, 0x47, 0x4f, 0x89, 0x97, 0x79, 0xf9, 0x80, 0xb4, 0x4b, 0xf4, 0x1b, 0xc2, 0x43, 0x59, + 0x35, 0x54, 0x24, 0xbd, 0xcc, 0xcf, 0x07, 0xc4, 0x54, 0xf8, 0x0e, 0xa2, 0xfb, 0xd6, 0x8a, 0xd0, + 0xd7, 0x86, 0x0a, 0x89, 0xfe, 0x41, 0x7f, 0xa3, 0x3c, 0x44, 0xe2, 0x65, 0x7e, 0x3e, 0x2c, 0x62, + 0xdd, 0x63, 0xae, 0x9d, 0x49, 0xb7, 0x8b, 0x12, 0xe8, 0xef, 0xcb, 0x53, 0xc5, 0xca, 0x75, 0xd2, + 0xcb, 0xbc, 0x3c, 0x22, 0x5d, 0x89, 0xff, 0x43, 0x6c, 0x2c, 0xc5, 0x9e, 0xd5, 0x82, 0xb6, 0xd2, + 0x36, 0xae, 0xa4, 0xb5, 0x4a, 0x14, 0x90, 0xae, 0xc4, 0x0f, 0x80, 0x94, 0xd4, 0x98, 0x7f, 0x37, + 0xc3, 0x0c, 0x40, 0xc8, 0x52, 0x36, 0xe2, 0x8a, 0xad, 0xa9, 0x8a, 0x11, 0x10, 0x8b, 0xe0, 0x29, + 0x4c, 0x1c, 0x7b, 0x9d, 0x07, 0x8f, 0x20, 0xba, 0xa9, 0x1a, 0xb1, 0x31, 0xfd, 0xf0, 0x18, 0x62, + 0x53, 0x1b, 0xc1, 0x18, 0xe2, 0xc5, 0xf6, 0xb9, 0x5c, 0xed, 0x3a, 0xc5, 0x5b, 0x0f, 0x46, 0x1d, + 0x31, 0x87, 0x9a, 0x01, 0xac, 0x58, 0x5d, 0x2f, 0x29, 0x3f, 0x50, 0xae, 0xce, 0x15, 0x13, 0x8b, + 0x20, 0x0c, 0x51, 0xc5, 0x56, 0x65, 0x75, 0x4b, 0xe5, 0x91, 0xf1, 0x9d, 0x4a, 0x37, 0x20, 0x0e, + 0x43, 0x19, 0x0c, 0x55, 0xbd, 0x94, 0x7c, 0x5b, 0x3f, 0x25, 0xbe, 0x92, 0xd8, 0x08, 0xfd, 0x85, + 0x98, 0xd3, 0x17, 0x26, 0x69, 0x67, 0xf3, 0x43, 0x69, 0x5c, 0xd8, 0xf6, 0xd2, 0xc0, 0x18, 0x05, + 0xba, 0x97, 0xcd, 0xb4, 0xa6, 0xbd, 0x06, 0x93, 0x38, 0x54, 0x89, 0x1d, 0xd6, 0x6a, 0xf4, 0xbb, + 0x32, 0x9a, 0xbe, 0xd6, 0xd8, 0xac, 0x78, 0xf7, 0x20, 0x54, 0x97, 0xca, 0x51, 0x01, 0x81, 0x5a, + 0xa1, 0x89, 0x99, 0x8f, 0xfd, 0x92, 0xd2, 0x5f, 0x2e, 0x34, 0xd7, 0x76, 0x0d, 0x43, 0x6b, 0x24, + 0xe8, 0x8f, 0x2d, 0x72, 0x5e, 0x41, 0x9a, 0x7e, 0xb5, 0x65, 0x5c, 0x0a, 0x08, 0xd4, 0xc4, 0xce, + 0x9d, 0xed, 0x79, 0x9e, 0x3b, 0x3b, 0x43, 0x45, 0x97, 0x10, 0xea, 0x11, 0xa2, 0x6e, 0xdf, 0x99, + 0x71, 0x3a, 0xfd, 0x44, 0xf5, 0x6f, 0x8f, 0xa1, 0xa2, 0x17, 0x1f, 0x01, 0x00, 0x00, 0xff, 0xff, + 0x6f, 0xbe, 0x4a, 0x4f, 0x72, 0x03, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConnInterface + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion6 + +// WriterClient is the client API for Writer service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type WriterClient interface { + Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) + WriteHeader(ctx context.Context, in *WriteHeaderRequest, opts ...grpc.CallOption) (*WriteHeaderResponse, error) + Flush(ctx context.Context, in *FlushRequest, opts ...grpc.CallOption) (*FlushResponse, error) + Hijack(ctx context.Context, in *HijackRequest, opts ...grpc.CallOption) (*HijackResponse, error) +} + +type writerClient struct { + cc grpc.ClientConnInterface +} + +func NewWriterClient(cc grpc.ClientConnInterface) WriterClient { + return &writerClient{cc} +} + +func (c *writerClient) Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) { + out := new(WriteResponse) + err := c.cc.Invoke(ctx, "/proto.Writer/Write", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *writerClient) WriteHeader(ctx context.Context, in *WriteHeaderRequest, opts ...grpc.CallOption) (*WriteHeaderResponse, error) { + out := new(WriteHeaderResponse) + err := c.cc.Invoke(ctx, "/proto.Writer/WriteHeader", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *writerClient) Flush(ctx context.Context, in *FlushRequest, opts ...grpc.CallOption) (*FlushResponse, error) { + out := new(FlushResponse) + err := c.cc.Invoke(ctx, "/proto.Writer/Flush", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *writerClient) Hijack(ctx context.Context, in *HijackRequest, opts ...grpc.CallOption) (*HijackResponse, error) { + out := new(HijackResponse) + err := c.cc.Invoke(ctx, "/proto.Writer/Hijack", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// WriterServer is the server API for Writer service. +type WriterServer interface { + Write(context.Context, *WriteRequest) (*WriteResponse, error) + WriteHeader(context.Context, *WriteHeaderRequest) (*WriteHeaderResponse, error) + Flush(context.Context, *FlushRequest) (*FlushResponse, error) + Hijack(context.Context, *HijackRequest) (*HijackResponse, error) +} + +// UnimplementedWriterServer can be embedded to have forward compatible implementations. +type UnimplementedWriterServer struct { +} + +func (*UnimplementedWriterServer) Write(ctx context.Context, req *WriteRequest) (*WriteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Write not implemented") +} +func (*UnimplementedWriterServer) WriteHeader(ctx context.Context, req *WriteHeaderRequest) (*WriteHeaderResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method WriteHeader not implemented") +} +func (*UnimplementedWriterServer) Flush(ctx context.Context, req *FlushRequest) (*FlushResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Flush not implemented") +} +func (*UnimplementedWriterServer) Hijack(ctx context.Context, req *HijackRequest) (*HijackResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Hijack not implemented") +} + +func RegisterWriterServer(s *grpc.Server, srv WriterServer) { + s.RegisterService(&_Writer_serviceDesc, srv) +} + +func _Writer_Write_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(WriteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WriterServer).Write(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Writer/Write", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WriterServer).Write(ctx, req.(*WriteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Writer_WriteHeader_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(WriteHeaderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WriterServer).WriteHeader(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Writer/WriteHeader", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WriterServer).WriteHeader(ctx, req.(*WriteHeaderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Writer_Flush_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(FlushRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WriterServer).Flush(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Writer/Flush", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WriterServer).Flush(ctx, req.(*FlushRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Writer_Hijack_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(HijackRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WriterServer).Hijack(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Writer/Hijack", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WriterServer).Hijack(ctx, req.(*HijackRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Writer_serviceDesc = grpc.ServiceDesc{ + ServiceName: "proto.Writer", + HandlerType: (*WriterServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Write", + Handler: _Writer_Write_Handler, + }, + { + MethodName: "WriteHeader", + Handler: _Writer_WriteHeader_Handler, + }, + { + MethodName: "Flush", + Handler: _Writer_Flush_Handler, + }, + { + MethodName: "Hijack", + Handler: _Writer_Hijack_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "writer.proto", +} diff --git a/vms/rpcchainvm/ghttp/gresponsewriter/proto/writer.proto b/vms/rpcchainvm/ghttp/gresponsewriter/proto/writer.proto new file mode 100644 index 0000000..121c661 --- /dev/null +++ b/vms/rpcchainvm/ghttp/gresponsewriter/proto/writer.proto @@ -0,0 +1,46 @@ +syntax = "proto3"; +package proto; + +message Header { + string key = 1; + repeated string values = 2; +} + +message WriteRequest { + repeated Header headers = 1; + bytes payload = 2; +} + +message WriteResponse { + int32 written = 1; +} + +message WriteHeaderRequest { + repeated Header headers = 1; + int32 statusCode = 2; +} + +message WriteHeaderResponse {} + +message FlushRequest {} + +message FlushResponse {} + +message HijackRequest {} + +message HijackResponse { + uint32 connServer = 1; + string localNetwork = 2; + string localString = 3; + string remoteNetwork = 4; + string remoteString = 5; + uint32 readerServer = 6; + uint32 writerServer = 7; +} + +service Writer { + rpc Write(WriteRequest) returns (WriteResponse); + rpc WriteHeader(WriteHeaderRequest) returns (WriteHeaderResponse); + rpc Flush(FlushRequest) returns (FlushResponse); + rpc Hijack(HijackRequest) returns (HijackResponse); +} \ No newline at end of file diff --git a/vms/rpcchainvm/ghttp/gresponsewriter/writer_client.go b/vms/rpcchainvm/ghttp/gresponsewriter/writer_client.go new file mode 100644 index 0000000..bcd880b --- /dev/null +++ b/vms/rpcchainvm/ghttp/gresponsewriter/writer_client.go @@ -0,0 +1,134 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package gresponsewriter + +import ( + "bufio" + "context" + "net" + "net/http" + + "github.com/hashicorp/go-plugin" + + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gconn" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greader" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gwriter" + + connproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gconn/proto" + readerproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greader/proto" + responsewriterproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gresponsewriter/proto" + writerproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gwriter/proto" +) + +// Client is an implementation of a messenger channel that talks over RPC. +type Client struct { + client responsewriterproto.WriterClient + header http.Header + broker *plugin.GRPCBroker +} + +// NewClient returns a database instance connected to a remote database instance +func NewClient(client responsewriterproto.WriterClient, broker *plugin.GRPCBroker) *Client { + return &Client{ + client: client, + header: make(http.Header), + broker: broker, + } +} + +// Header ... +func (c *Client) Header() http.Header { return c.header } + +// Write ... +func (c *Client) Write(payload []byte) (int, error) { + req := &responsewriterproto.WriteRequest{ + Headers: make([]*responsewriterproto.Header, 0, len(c.header)), + Payload: payload, + } + for key, values := range c.header { + req.Headers = append(req.Headers, &responsewriterproto.Header{ + Key: key, + Values: values, + }) + } + resp, err := c.client.Write(context.Background(), req) + if err != nil { + return 0, err + } + return int(resp.Written), nil +} + +// WriteHeader ... +func (c *Client) WriteHeader(statusCode int) { + req := &responsewriterproto.WriteHeaderRequest{ + Headers: make([]*responsewriterproto.Header, 0, len(c.header)), + StatusCode: int32(statusCode), + } + for key, values := range c.header { + req.Headers = append(req.Headers, &responsewriterproto.Header{ + Key: key, + Values: values, + }) + } + // TODO: How should we handle an error here? + c.client.WriteHeader(context.Background(), req) +} + +// Flush ... +func (c *Client) Flush() { + // TODO: How should we handle an error here? + c.client.Flush(context.Background(), &responsewriterproto.FlushRequest{}) +} + +type addr struct { + network string + str string +} + +func (a *addr) Network() string { return a.network } +func (a *addr) String() string { return a.str } + +// Hijack ... +func (c *Client) Hijack() (net.Conn, *bufio.ReadWriter, error) { + resp, err := c.client.Hijack(context.Background(), &responsewriterproto.HijackRequest{}) + if err != nil { + return nil, nil, err + } + + connConn, err := c.broker.Dial(resp.ConnServer) + if err != nil { + return nil, nil, err + } + + readerConn, err := c.broker.Dial(resp.ReaderServer) + if err != nil { + connConn.Close() + return nil, nil, err + } + + writerConn, err := c.broker.Dial(resp.WriterServer) + if err != nil { + connConn.Close() + readerConn.Close() + return nil, nil, err + } + + conn := gconn.NewClient(connproto.NewConnClient(connConn), &addr{ + network: resp.LocalNetwork, + str: resp.LocalString, + }, &addr{ + network: resp.RemoteNetwork, + str: resp.RemoteString, + }, connConn, readerConn, writerConn) + + reader := greader.NewClient(readerproto.NewReaderClient(readerConn)) + writer := gwriter.NewClient(writerproto.NewWriterClient(writerConn)) + + readWriter := bufio.NewReadWriter( + bufio.NewReader(reader), + bufio.NewWriter(writer), + ) + + return conn, readWriter, nil +} diff --git a/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go b/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go new file mode 100644 index 0000000..296fad2 --- /dev/null +++ b/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go @@ -0,0 +1,123 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package gresponsewriter + +import ( + "context" + "errors" + "net/http" + + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gconn" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greader" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gwriter" + + "github.com/hashicorp/go-plugin" + "google.golang.org/grpc" + + connproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gconn/proto" + readerproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greader/proto" + responsewriterproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gresponsewriter/proto" + writerproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gwriter/proto" +) + +// Server is a http.Handler that is managed over RPC. +type Server struct { + writer http.ResponseWriter + broker *plugin.GRPCBroker +} + +// NewServer returns a http.Handler instance manage remotely +func NewServer(writer http.ResponseWriter, broker *plugin.GRPCBroker) *Server { + return &Server{ + writer: writer, + broker: broker, + } +} + +// Write ... +func (s *Server) Write(ctx context.Context, req *responsewriterproto.WriteRequest) (*responsewriterproto.WriteResponse, error) { + headers := s.writer.Header() + for key := range headers { + delete(headers, key) + } + for _, header := range req.Headers { + headers[header.Key] = header.Values + } + + n, err := s.writer.Write(req.Payload) + if err != nil { + return nil, err + } + return &responsewriterproto.WriteResponse{ + Written: int32(n), + }, nil +} + +// WriteHeader ... +func (s *Server) WriteHeader(ctx context.Context, req *responsewriterproto.WriteHeaderRequest) (*responsewriterproto.WriteHeaderResponse, error) { + headers := s.writer.Header() + for key := range headers { + delete(headers, key) + } + for _, header := range req.Headers { + headers[header.Key] = header.Values + } + s.writer.WriteHeader(int(req.StatusCode)) + return &responsewriterproto.WriteHeaderResponse{}, nil +} + +// Flush ... +func (s *Server) Flush(ctx context.Context, req *responsewriterproto.FlushRequest) (*responsewriterproto.FlushResponse, error) { + flusher, ok := s.writer.(http.Flusher) + if !ok { + return nil, errors.New("response writer doesn't support flushing") + } + flusher.Flush() + return &responsewriterproto.FlushResponse{}, nil +} + +// Hijack ... +func (s *Server) Hijack(ctx context.Context, req *responsewriterproto.HijackRequest) (*responsewriterproto.HijackResponse, error) { + hijacker, ok := s.writer.(http.Hijacker) + if !ok { + return nil, errors.New("response writer doesn't support hijacking") + } + conn, readWriter, err := hijacker.Hijack() + if err != nil { + return nil, err + } + + connID := s.broker.NextId() + readerID := s.broker.NextId() + writerID := s.broker.NextId() + + go s.broker.AcceptAndServe(connID, func(opts []grpc.ServerOption) *grpc.Server { + connServer := grpc.NewServer(opts...) + connproto.RegisterConnServer(connServer, gconn.NewServer(conn)) + return connServer + }) + go s.broker.AcceptAndServe(readerID, func(opts []grpc.ServerOption) *grpc.Server { + readerServer := grpc.NewServer(opts...) + readerproto.RegisterReaderServer(readerServer, greader.NewServer(readWriter)) + return readerServer + }) + go s.broker.AcceptAndServe(writerID, func(opts []grpc.ServerOption) *grpc.Server { + writerServer := grpc.NewServer(opts...) + writerproto.RegisterWriterServer(writerServer, gwriter.NewServer(readWriter)) + return writerServer + }) + + local := conn.LocalAddr() + remote := conn.RemoteAddr() + + return &responsewriterproto.HijackResponse{ + ConnServer: connID, + LocalNetwork: local.Network(), + LocalString: local.String(), + RemoteNetwork: remote.Network(), + RemoteString: remote.String(), + ReaderServer: readerID, + WriterServer: writerID, + }, nil +} diff --git a/vms/rpcchainvm/ghttp/gwriter/proto/writer.pb.go b/vms/rpcchainvm/ghttp/gwriter/proto/writer.pb.go new file mode 100644 index 0000000..fe0e7bf --- /dev/null +++ b/vms/rpcchainvm/ghttp/gwriter/proto/writer.pb.go @@ -0,0 +1,221 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: writer.proto + +package proto + +import ( + context "context" + fmt "fmt" + proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type WriteRequest struct { + Payload []byte `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *WriteRequest) Reset() { *m = WriteRequest{} } +func (m *WriteRequest) String() string { return proto.CompactTextString(m) } +func (*WriteRequest) ProtoMessage() {} +func (*WriteRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ea6fbe89c42e6759, []int{0} +} + +func (m *WriteRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_WriteRequest.Unmarshal(m, b) +} +func (m *WriteRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_WriteRequest.Marshal(b, m, deterministic) +} +func (m *WriteRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_WriteRequest.Merge(m, src) +} +func (m *WriteRequest) XXX_Size() int { + return xxx_messageInfo_WriteRequest.Size(m) +} +func (m *WriteRequest) XXX_DiscardUnknown() { + xxx_messageInfo_WriteRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_WriteRequest proto.InternalMessageInfo + +func (m *WriteRequest) GetPayload() []byte { + if m != nil { + return m.Payload + } + return nil +} + +type WriteResponse struct { + Written int32 `protobuf:"varint,1,opt,name=written,proto3" json:"written,omitempty"` + Error string `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"` + Errored bool `protobuf:"varint,3,opt,name=errored,proto3" json:"errored,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *WriteResponse) Reset() { *m = WriteResponse{} } +func (m *WriteResponse) String() string { return proto.CompactTextString(m) } +func (*WriteResponse) ProtoMessage() {} +func (*WriteResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ea6fbe89c42e6759, []int{1} +} + +func (m *WriteResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_WriteResponse.Unmarshal(m, b) +} +func (m *WriteResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_WriteResponse.Marshal(b, m, deterministic) +} +func (m *WriteResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_WriteResponse.Merge(m, src) +} +func (m *WriteResponse) XXX_Size() int { + return xxx_messageInfo_WriteResponse.Size(m) +} +func (m *WriteResponse) XXX_DiscardUnknown() { + xxx_messageInfo_WriteResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_WriteResponse proto.InternalMessageInfo + +func (m *WriteResponse) GetWritten() int32 { + if m != nil { + return m.Written + } + return 0 +} + +func (m *WriteResponse) GetError() string { + if m != nil { + return m.Error + } + return "" +} + +func (m *WriteResponse) GetErrored() bool { + if m != nil { + return m.Errored + } + return false +} + +func init() { + proto.RegisterType((*WriteRequest)(nil), "proto.WriteRequest") + proto.RegisterType((*WriteResponse)(nil), "proto.WriteResponse") +} + +func init() { proto.RegisterFile("writer.proto", fileDescriptor_ea6fbe89c42e6759) } + +var fileDescriptor_ea6fbe89c42e6759 = []byte{ + // 164 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0x2f, 0xca, 0x2c, + 0x49, 0x2d, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, 0x4a, 0x1a, 0x5c, 0x3c, + 0xe1, 0x20, 0xe1, 0xa0, 0xd4, 0xc2, 0xd2, 0xd4, 0xe2, 0x12, 0x21, 0x09, 0x2e, 0xf6, 0x82, 0xc4, + 0xca, 0x9c, 0xfc, 0xc4, 0x14, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x9e, 0x20, 0x18, 0x57, 0x29, 0x92, + 0x8b, 0x17, 0xaa, 0xb2, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x15, 0xa4, 0x14, 0x64, 0x62, 0x49, 0x6a, + 0x1e, 0x58, 0x29, 0x6b, 0x10, 0x8c, 0x2b, 0x24, 0xc2, 0xc5, 0x9a, 0x5a, 0x54, 0x94, 0x5f, 0x24, + 0xc1, 0xa4, 0xc0, 0xa8, 0xc1, 0x19, 0x04, 0xe1, 0x80, 0xd4, 0x83, 0x19, 0xa9, 0x29, 0x12, 0xcc, + 0x0a, 0x8c, 0x1a, 0x1c, 0x41, 0x30, 0xae, 0x91, 0x0d, 0x17, 0x1b, 0xd8, 0xe8, 0x22, 0x21, 0x23, + 0x2e, 0x56, 0x30, 0x4b, 0x48, 0x18, 0xe2, 0x4c, 0x3d, 0x64, 0xc7, 0x49, 0x89, 0xa0, 0x0a, 0x42, + 0xdc, 0x91, 0xc4, 0x06, 0x16, 0x34, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x3e, 0x3f, 0xbb, 0x2f, + 0xe0, 0x00, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConnInterface + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion6 + +// WriterClient is the client API for Writer service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type WriterClient interface { + Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) +} + +type writerClient struct { + cc grpc.ClientConnInterface +} + +func NewWriterClient(cc grpc.ClientConnInterface) WriterClient { + return &writerClient{cc} +} + +func (c *writerClient) Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) { + out := new(WriteResponse) + err := c.cc.Invoke(ctx, "/proto.Writer/Write", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// WriterServer is the server API for Writer service. +type WriterServer interface { + Write(context.Context, *WriteRequest) (*WriteResponse, error) +} + +// UnimplementedWriterServer can be embedded to have forward compatible implementations. +type UnimplementedWriterServer struct { +} + +func (*UnimplementedWriterServer) Write(ctx context.Context, req *WriteRequest) (*WriteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Write not implemented") +} + +func RegisterWriterServer(s *grpc.Server, srv WriterServer) { + s.RegisterService(&_Writer_serviceDesc, srv) +} + +func _Writer_Write_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(WriteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WriterServer).Write(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Writer/Write", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WriterServer).Write(ctx, req.(*WriteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Writer_serviceDesc = grpc.ServiceDesc{ + ServiceName: "proto.Writer", + HandlerType: (*WriterServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Write", + Handler: _Writer_Write_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "writer.proto", +} diff --git a/vms/rpcchainvm/ghttp/gwriter/proto/writer.proto b/vms/rpcchainvm/ghttp/gwriter/proto/writer.proto new file mode 100644 index 0000000..0baa7d6 --- /dev/null +++ b/vms/rpcchainvm/ghttp/gwriter/proto/writer.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; +package proto; + +message WriteRequest { + bytes payload = 1; +} + +message WriteResponse { + int32 written = 1; + string error = 2; + bool errored = 3; +} + +service Writer { + rpc Write(WriteRequest) returns (WriteResponse); +} \ No newline at end of file diff --git a/vms/rpcchainvm/ghttp/gwriter/writer_client.go b/vms/rpcchainvm/ghttp/gwriter/writer_client.go new file mode 100644 index 0000000..f229a3d --- /dev/null +++ b/vms/rpcchainvm/ghttp/gwriter/writer_client.go @@ -0,0 +1,34 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package gwriter + +import ( + "context" + "errors" + + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gwriter/proto" +) + +// Client is an implementation of a messenger channel that talks over RPC. +type Client struct{ client proto.WriterClient } + +// NewClient returns a database instance connected to a remote database instance +func NewClient(client proto.WriterClient) *Client { + return &Client{client: client} +} + +// Write ... +func (c *Client) Write(p []byte) (int, error) { + resp, err := c.client.Write(context.Background(), &proto.WriteRequest{ + Payload: p, + }) + if err != nil { + return 0, err + } + + if resp.Errored { + err = errors.New(resp.Error) + } + return int(resp.Written), err +} diff --git a/vms/rpcchainvm/ghttp/gwriter/writer_server.go b/vms/rpcchainvm/ghttp/gwriter/writer_server.go new file mode 100644 index 0000000..5d1d800 --- /dev/null +++ b/vms/rpcchainvm/ghttp/gwriter/writer_server.go @@ -0,0 +1,32 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package gwriter + +import ( + "context" + "io" + + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gwriter/proto" +) + +// Server is a http.Handler that is managed over RPC. +type Server struct{ writer io.Writer } + +// NewServer returns a http.Handler instance manage remotely +func NewServer(writer io.Writer) *Server { + return &Server{writer: writer} +} + +// Write ... +func (s *Server) Write(ctx context.Context, req *proto.WriteRequest) (*proto.WriteResponse, error) { + n, err := s.writer.Write(req.Payload) + resp := &proto.WriteResponse{ + Written: int32(n), + } + if err != nil { + resp.Errored = true + resp.Error = err.Error() + } + return resp, nil +} diff --git a/vms/rpcchainvm/ghttp/http_client.go b/vms/rpcchainvm/ghttp/http_client.go index e06ef2c..edb8347 100644 --- a/vms/rpcchainvm/ghttp/http_client.go +++ b/vms/rpcchainvm/ghttp/http_client.go @@ -4,61 +4,149 @@ package ghttp import ( - "io/ioutil" "net/http" - "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/proto" + "google.golang.org/grpc" + + "github.com/hashicorp/go-plugin" + + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greadcloser" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gresponsewriter" + + readcloserproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greadcloser/proto" + responsewriterproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gresponsewriter/proto" + httpproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/proto" ) // Client is an implementation of a messenger channel that talks over RPC. -type Client struct{ client proto.HTTPClient } +type Client struct { + client httpproto.HTTPClient + broker *plugin.GRPCBroker +} // NewClient returns a database instance connected to a remote database instance -func NewClient(client proto.HTTPClient) *Client { - return &Client{client: client} +func NewClient(client httpproto.HTTPClient, broker *plugin.GRPCBroker) *Client { + return &Client{ + client: client, + broker: broker, + } } // Handle ... func (c *Client) ServeHTTP(w http.ResponseWriter, r *http.Request) { - // get the headers - inboundHeaders := make([]*proto.Header, len(r.Header))[:0] + var reader *grpc.Server + var writer *grpc.Server + + readerID := c.broker.NextId() + go c.broker.AcceptAndServe(readerID, func(opts []grpc.ServerOption) *grpc.Server { + reader = grpc.NewServer(opts...) + readcloserproto.RegisterReaderServer(reader, greadcloser.NewServer(r.Body)) + + return reader + }) + writerID := c.broker.NextId() + go c.broker.AcceptAndServe(writerID, func(opts []grpc.ServerOption) *grpc.Server { + writer = grpc.NewServer(opts...) + responsewriterproto.RegisterWriterServer(writer, gresponsewriter.NewServer(w, c.broker)) + + return writer + }) + + req := &httpproto.HTTPRequest{ + ResponseWriter: writerID, + Request: &httpproto.Request{ + Method: r.Method, + Proto: r.Proto, + ProtoMajor: int32(r.ProtoMajor), + ProtoMinor: int32(r.ProtoMinor), + Body: readerID, + ContentLength: r.ContentLength, + TransferEncoding: r.TransferEncoding, + Host: r.Host, + RemoteAddr: r.RemoteAddr, + RequestURI: r.RequestURI, + }, + } + req.Request.Header = make([]*httpproto.Element, 0, len(r.Header)) for key, values := range r.Header { - inboundHeaders = append(inboundHeaders, &proto.Header{ + req.Request.Header = append(req.Request.Header, &httpproto.Element{ Key: key, Values: values, }) } - // get the body - body, err := ioutil.ReadAll(r.Body) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return + req.Request.Form = make([]*httpproto.Element, 0, len(r.Form)) + for key, values := range r.Form { + req.Request.Form = append(req.Request.Form, &httpproto.Element{ + Key: key, + Values: values, + }) } - // execute the call - resp, err := c.client.Handle(r.Context(), &proto.HTTPRequest{ - Url: r.RequestURI, - Method: r.Method, - Headers: inboundHeaders, - Body: body, - }) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return + req.Request.PostForm = make([]*httpproto.Element, 0, len(r.PostForm)) + for key, values := range r.PostForm { + req.Request.PostForm = append(req.Request.PostForm, &httpproto.Element{ + Key: key, + Values: values, + }) } - // return the code - w.WriteHeader(int(resp.Code)) + if r.URL != nil { + req.Request.Url = &httpproto.URL{ + Scheme: r.URL.Scheme, + Opaque: r.URL.Opaque, + Host: r.URL.Host, + Path: r.URL.Path, + RawPath: r.URL.RawPath, + ForceQuery: r.URL.ForceQuery, + RawQuery: r.URL.RawQuery, + Fragment: r.URL.Fragment, + } - // return the headers - outboundHeaders := w.Header() - for _, header := range resp.Headers { - outboundHeaders[header.Key] = header.Values + if r.URL.User != nil { + req.Request.Url.User = &httpproto.Userinfo{ + Username: r.URL.User.Username(), + } + pwd, set := r.URL.User.Password() + req.Request.Url.User.Password = pwd + req.Request.Url.User.PasswordSet = set + } } - // return the body - if _, err := w.Write(resp.Body); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + if r.TLS != nil { + req.Request.Tls = &httpproto.ConnectionState{ + Version: uint32(r.TLS.Version), + HandshakeComplete: r.TLS.HandshakeComplete, + DidResume: r.TLS.DidResume, + CipherSuite: uint32(r.TLS.CipherSuite), + NegotiatedProtocol: r.TLS.NegotiatedProtocol, + NegotiatedProtocolIsMutual: r.TLS.NegotiatedProtocolIsMutual, + ServerName: r.TLS.ServerName, + SignedCertificateTimestamps: r.TLS.SignedCertificateTimestamps, + OcspResponse: r.TLS.OCSPResponse, + TlsUnique: r.TLS.TLSUnique, + } + + req.Request.Tls.PeerCertificates = &httpproto.Certificates{ + Cert: make([][]byte, len(r.TLS.PeerCertificates)), + } + for i, cert := range r.TLS.PeerCertificates { + req.Request.Tls.PeerCertificates.Cert[i] = cert.Raw + } + + req.Request.Tls.VerifiedChains = make([]*httpproto.Certificates, len(r.TLS.VerifiedChains)) + for i, chain := range r.TLS.VerifiedChains { + req.Request.Tls.VerifiedChains[i] = &httpproto.Certificates{ + Cert: make([][]byte, len(chain)), + } + for j, cert := range chain { + req.Request.Tls.VerifiedChains[i].Cert[j] = cert.Raw + } + } } + + c.client.Handle(r.Context(), req) + + reader.Stop() + writer.Stop() } diff --git a/vms/rpcchainvm/ghttp/http_server.go b/vms/rpcchainvm/ghttp/http_server.go index 0ee8eb0..ae1af60 100644 --- a/vms/rpcchainvm/ghttp/http_server.go +++ b/vms/rpcchainvm/ghttp/http_server.go @@ -4,59 +4,144 @@ package ghttp import ( - "bytes" "context" - "io/ioutil" + "crypto/tls" + "crypto/x509" "net/http" - "net/http/httptest" + "net/url" - "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/proto" + "github.com/hashicorp/go-plugin" + + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greadcloser" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gresponsewriter" + + readcloserproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greadcloser/proto" + responsewriterproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gresponsewriter/proto" + httpproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/proto" ) // Server is a http.Handler that is managed over RPC. -type Server struct{ handler http.Handler } +type Server struct { + handler http.Handler + broker *plugin.GRPCBroker +} // NewServer returns a http.Handler instance manage remotely -func NewServer(handler http.Handler) *Server { - return &Server{handler: handler} +func NewServer(handler http.Handler, broker *plugin.GRPCBroker) *Server { + return &Server{ + handler: handler, + broker: broker, + } } // Handle ... -func (s Server) Handle(ctx context.Context, req *proto.HTTPRequest) (*proto.HTTPResponse, error) { +func (s *Server) Handle(ctx context.Context, req *httpproto.HTTPRequest) (*httpproto.HTTPResponse, error) { + writerConn, err := s.broker.Dial(req.ResponseWriter) + if err != nil { + return nil, err + } + defer writerConn.Close() + + readerConn, err := s.broker.Dial(req.Request.Body) + if err != nil { + return nil, err + } + defer readerConn.Close() + + writer := gresponsewriter.NewClient(responsewriterproto.NewWriterClient(writerConn), s.broker) + reader := greadcloser.NewClient(readcloserproto.NewReaderClient(readerConn)) + // create the request with the current context - r, err := http.NewRequestWithContext( + request, err := http.NewRequestWithContext( ctx, - req.Method, - req.Url, - ioutil.NopCloser(bytes.NewReader(req.Body)), + req.Request.Method, + req.Request.RequestURI, + reader, ) if err != nil { return nil, err } - // populate the headers - for _, header := range req.Headers { - r.Header[header.Key] = header.Values + if req.Request.Url != nil { + request.URL = &url.URL{ + Scheme: req.Request.Url.Scheme, + Opaque: req.Request.Url.Opaque, + Host: req.Request.Url.Host, + Path: req.Request.Url.Path, + RawPath: req.Request.Url.RawPath, + ForceQuery: req.Request.Url.ForceQuery, + RawQuery: req.Request.Url.RawQuery, + Fragment: req.Request.Url.Fragment, + } + if req.Request.Url.User != nil { + if req.Request.Url.User.PasswordSet { + request.URL.User = url.UserPassword(req.Request.Url.User.Username, req.Request.Url.User.Password) + } else { + request.URL.User = url.User(req.Request.Url.User.Username) + } + } } - // send the request to the recorder - recorder := httptest.NewRecorder() - s.handler.ServeHTTP(recorder, r) - - // get the returned headers - returnedHeaders := recorder.Header() - headers := make([]*proto.Header, len(returnedHeaders))[:0] - for key, values := range returnedHeaders { - headers = append(headers, &proto.Header{ - Key: key, - Values: values, - }) + request.Proto = req.Request.Proto + request.ProtoMajor = int(req.Request.ProtoMajor) + request.ProtoMinor = int(req.Request.ProtoMinor) + request.Header = make(http.Header, len(req.Request.Header)) + for _, elem := range req.Request.Header { + request.Header[elem.Key] = elem.Values } + request.ContentLength = req.Request.ContentLength + request.TransferEncoding = req.Request.TransferEncoding + request.Host = req.Request.Host + request.Form = make(url.Values, len(req.Request.Form)) + for _, elem := range req.Request.Form { + request.Form[elem.Key] = elem.Values + } + request.PostForm = make(url.Values, len(req.Request.PostForm)) + for _, elem := range req.Request.PostForm { + request.PostForm[elem.Key] = elem.Values + } + request.Trailer = make(http.Header) + request.RemoteAddr = req.Request.RemoteAddr + request.RequestURI = req.Request.RequestURI + + if req.Request.Tls != nil { + request.TLS = &tls.ConnectionState{ + Version: uint16(req.Request.Tls.Version), + HandshakeComplete: req.Request.Tls.HandshakeComplete, + DidResume: req.Request.Tls.DidResume, + CipherSuite: uint16(req.Request.Tls.CipherSuite), + NegotiatedProtocol: req.Request.Tls.NegotiatedProtocol, + NegotiatedProtocolIsMutual: req.Request.Tls.NegotiatedProtocolIsMutual, + ServerName: req.Request.Tls.ServerName, + SignedCertificateTimestamps: req.Request.Tls.SignedCertificateTimestamps, + OCSPResponse: req.Request.Tls.OcspResponse, + TLSUnique: req.Request.Tls.TlsUnique, + } + + request.TLS.PeerCertificates = make([]*x509.Certificate, len(req.Request.Tls.PeerCertificates.Cert)) + for i, certBytes := range req.Request.Tls.PeerCertificates.Cert { + cert, err := x509.ParseCertificate(certBytes) + if err != nil { + return nil, err + } + request.TLS.PeerCertificates[i] = cert + } + + request.TLS.VerifiedChains = make([][]*x509.Certificate, len(req.Request.Tls.VerifiedChains)) + for i, chain := range req.Request.Tls.VerifiedChains { + request.TLS.VerifiedChains[i] = make([]*x509.Certificate, len(chain.Cert)) + for j, certBytes := range chain.Cert { + cert, err := x509.ParseCertificate(certBytes) + if err != nil { + return nil, err + } + request.TLS.VerifiedChains[i][j] = cert + } + } + } + + s.handler.ServeHTTP(writer, request) // return the response - return &proto.HTTPResponse{ - Code: int32(recorder.Code), - Headers: headers, - Body: recorder.Body.Bytes(), - }, nil + return &httpproto.HTTPResponse{}, nil } diff --git a/vms/rpcchainvm/ghttp/http_test.go b/vms/rpcchainvm/ghttp/http_test.go deleted file mode 100644 index 0c60f27..0000000 --- a/vms/rpcchainvm/ghttp/http_test.go +++ /dev/null @@ -1,96 +0,0 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package ghttp - -import ( - "bytes" - "log" - "net" - "net/http" - "net/http/httptest" - "testing" - - "golang.org/x/net/context" - - "google.golang.org/grpc" - "google.golang.org/grpc/test/bufconn" - - "github.com/gorilla/rpc/v2" - "github.com/gorilla/rpc/v2/json2" - - "github.com/ava-labs/gecko/utils/json" - "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/proto" -) - -const ( - bufSize = 1 << 20 -) - -type service struct{} - -type Args struct{} - -type Reply struct { - Called bool -} - -func (s *service) Call(r *http.Request, args *Args, reply *Reply) error { - reply.Called = true - return nil -} - -func TestRPC(t *testing.T) { - rpcServer := rpc.NewServer() - codec := json.NewCodec() - rpcServer.RegisterCodec(codec, "application/json") - rpcServer.RegisterCodec(codec, "application/json;charset=UTF-8") - rpcServer.RegisterService(&service{}, "service") - - listener := bufconn.Listen(bufSize) - server := grpc.NewServer() - proto.RegisterHTTPServer(server, NewServer(rpcServer)) - go func() { - if err := server.Serve(listener); err != nil { - log.Fatal(err) - } - }() - - dialer := grpc.WithContextDialer( - func(context.Context, string) (net.Conn, error) { - return listener.Dial() - }) - - ctx := context.Background() - conn, err := grpc.DialContext(ctx, "", dialer, grpc.WithInsecure()) - if err != nil { - t.Fatal(err) - } - defer conn.Close() - - rpcClient := NewClient(proto.NewHTTPClient(conn)) - - req := &Args{} - buf, err := json2.EncodeClientRequest("service.call", req) - if err != nil { - t.Fatal(err) - } - body := bytes.NewBuffer(buf) - r, err := http.NewRequest("POST", "http://localhost:8080/", body) - if err != nil { - t.Fatal(err) - } - r.Header.Set("Content-Type", "application/json") - - w := httptest.NewRecorder() - rpcClient.ServeHTTP(w, r) - - res := &Reply{} - if err := json2.DecodeClientResponse(w.Body, res); err != nil { - t.Fatal(err) - } - - if !res.Called { - t.Fatalf("Should have called the function") - } -} diff --git a/vms/rpcchainvm/ghttp/proto/http.pb.go b/vms/rpcchainvm/ghttp/proto/http.pb.go index e654dde..013c3b4 100644 --- a/vms/rpcchainvm/ghttp/proto/http.pb.go +++ b/vms/rpcchainvm/ghttp/proto/http.pb.go @@ -24,7 +24,165 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package -type Header struct { +type Userinfo struct { + Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` + Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` + PasswordSet bool `protobuf:"varint,3,opt,name=passwordSet,proto3" json:"passwordSet,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Userinfo) Reset() { *m = Userinfo{} } +func (m *Userinfo) String() string { return proto.CompactTextString(m) } +func (*Userinfo) ProtoMessage() {} +func (*Userinfo) Descriptor() ([]byte, []int) { + return fileDescriptor_11b04836674e6f94, []int{0} +} + +func (m *Userinfo) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Userinfo.Unmarshal(m, b) +} +func (m *Userinfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Userinfo.Marshal(b, m, deterministic) +} +func (m *Userinfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_Userinfo.Merge(m, src) +} +func (m *Userinfo) XXX_Size() int { + return xxx_messageInfo_Userinfo.Size(m) +} +func (m *Userinfo) XXX_DiscardUnknown() { + xxx_messageInfo_Userinfo.DiscardUnknown(m) +} + +var xxx_messageInfo_Userinfo proto.InternalMessageInfo + +func (m *Userinfo) GetUsername() string { + if m != nil { + return m.Username + } + return "" +} + +func (m *Userinfo) GetPassword() string { + if m != nil { + return m.Password + } + return "" +} + +func (m *Userinfo) GetPasswordSet() bool { + if m != nil { + return m.PasswordSet + } + return false +} + +type URL struct { + Scheme string `protobuf:"bytes,1,opt,name=scheme,proto3" json:"scheme,omitempty"` + Opaque string `protobuf:"bytes,2,opt,name=opaque,proto3" json:"opaque,omitempty"` + User *Userinfo `protobuf:"bytes,3,opt,name=user,proto3" json:"user,omitempty"` + Host string `protobuf:"bytes,4,opt,name=host,proto3" json:"host,omitempty"` + Path string `protobuf:"bytes,5,opt,name=path,proto3" json:"path,omitempty"` + RawPath string `protobuf:"bytes,6,opt,name=rawPath,proto3" json:"rawPath,omitempty"` + ForceQuery bool `protobuf:"varint,7,opt,name=forceQuery,proto3" json:"forceQuery,omitempty"` + RawQuery string `protobuf:"bytes,8,opt,name=rawQuery,proto3" json:"rawQuery,omitempty"` + Fragment string `protobuf:"bytes,9,opt,name=fragment,proto3" json:"fragment,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *URL) Reset() { *m = URL{} } +func (m *URL) String() string { return proto.CompactTextString(m) } +func (*URL) ProtoMessage() {} +func (*URL) Descriptor() ([]byte, []int) { + return fileDescriptor_11b04836674e6f94, []int{1} +} + +func (m *URL) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_URL.Unmarshal(m, b) +} +func (m *URL) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_URL.Marshal(b, m, deterministic) +} +func (m *URL) XXX_Merge(src proto.Message) { + xxx_messageInfo_URL.Merge(m, src) +} +func (m *URL) XXX_Size() int { + return xxx_messageInfo_URL.Size(m) +} +func (m *URL) XXX_DiscardUnknown() { + xxx_messageInfo_URL.DiscardUnknown(m) +} + +var xxx_messageInfo_URL proto.InternalMessageInfo + +func (m *URL) GetScheme() string { + if m != nil { + return m.Scheme + } + return "" +} + +func (m *URL) GetOpaque() string { + if m != nil { + return m.Opaque + } + return "" +} + +func (m *URL) GetUser() *Userinfo { + if m != nil { + return m.User + } + return nil +} + +func (m *URL) GetHost() string { + if m != nil { + return m.Host + } + return "" +} + +func (m *URL) GetPath() string { + if m != nil { + return m.Path + } + return "" +} + +func (m *URL) GetRawPath() string { + if m != nil { + return m.RawPath + } + return "" +} + +func (m *URL) GetForceQuery() bool { + if m != nil { + return m.ForceQuery + } + return false +} + +func (m *URL) GetRawQuery() string { + if m != nil { + return m.RawQuery + } + return "" +} + +func (m *URL) GetFragment() string { + if m != nil { + return m.Fragment + } + return "" +} + +type Element struct { Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` Values []string `protobuf:"bytes,2,rep,name=values,proto3" json:"values,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -32,60 +190,383 @@ type Header struct { XXX_sizecache int32 `json:"-"` } -func (m *Header) Reset() { *m = Header{} } -func (m *Header) String() string { return proto.CompactTextString(m) } -func (*Header) ProtoMessage() {} -func (*Header) Descriptor() ([]byte, []int) { - return fileDescriptor_11b04836674e6f94, []int{0} +func (m *Element) Reset() { *m = Element{} } +func (m *Element) String() string { return proto.CompactTextString(m) } +func (*Element) ProtoMessage() {} +func (*Element) Descriptor() ([]byte, []int) { + return fileDescriptor_11b04836674e6f94, []int{2} } -func (m *Header) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Header.Unmarshal(m, b) +func (m *Element) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Element.Unmarshal(m, b) } -func (m *Header) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Header.Marshal(b, m, deterministic) +func (m *Element) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Element.Marshal(b, m, deterministic) } -func (m *Header) XXX_Merge(src proto.Message) { - xxx_messageInfo_Header.Merge(m, src) +func (m *Element) XXX_Merge(src proto.Message) { + xxx_messageInfo_Element.Merge(m, src) } -func (m *Header) XXX_Size() int { - return xxx_messageInfo_Header.Size(m) +func (m *Element) XXX_Size() int { + return xxx_messageInfo_Element.Size(m) } -func (m *Header) XXX_DiscardUnknown() { - xxx_messageInfo_Header.DiscardUnknown(m) +func (m *Element) XXX_DiscardUnknown() { + xxx_messageInfo_Element.DiscardUnknown(m) } -var xxx_messageInfo_Header proto.InternalMessageInfo +var xxx_messageInfo_Element proto.InternalMessageInfo -func (m *Header) GetKey() string { +func (m *Element) GetKey() string { if m != nil { return m.Key } return "" } -func (m *Header) GetValues() []string { +func (m *Element) GetValues() []string { if m != nil { return m.Values } return nil } +type Certificates struct { + Cert [][]byte `protobuf:"bytes,1,rep,name=cert,proto3" json:"cert,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Certificates) Reset() { *m = Certificates{} } +func (m *Certificates) String() string { return proto.CompactTextString(m) } +func (*Certificates) ProtoMessage() {} +func (*Certificates) Descriptor() ([]byte, []int) { + return fileDescriptor_11b04836674e6f94, []int{3} +} + +func (m *Certificates) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Certificates.Unmarshal(m, b) +} +func (m *Certificates) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Certificates.Marshal(b, m, deterministic) +} +func (m *Certificates) XXX_Merge(src proto.Message) { + xxx_messageInfo_Certificates.Merge(m, src) +} +func (m *Certificates) XXX_Size() int { + return xxx_messageInfo_Certificates.Size(m) +} +func (m *Certificates) XXX_DiscardUnknown() { + xxx_messageInfo_Certificates.DiscardUnknown(m) +} + +var xxx_messageInfo_Certificates proto.InternalMessageInfo + +func (m *Certificates) GetCert() [][]byte { + if m != nil { + return m.Cert + } + return nil +} + +type ConnectionState struct { + Version uint32 `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"` + HandshakeComplete bool `protobuf:"varint,2,opt,name=handshakeComplete,proto3" json:"handshakeComplete,omitempty"` + DidResume bool `protobuf:"varint,3,opt,name=didResume,proto3" json:"didResume,omitempty"` + CipherSuite uint32 `protobuf:"varint,4,opt,name=cipherSuite,proto3" json:"cipherSuite,omitempty"` + NegotiatedProtocol string `protobuf:"bytes,5,opt,name=negotiatedProtocol,proto3" json:"negotiatedProtocol,omitempty"` + NegotiatedProtocolIsMutual bool `protobuf:"varint,6,opt,name=negotiatedProtocolIsMutual,proto3" json:"negotiatedProtocolIsMutual,omitempty"` + ServerName string `protobuf:"bytes,7,opt,name=serverName,proto3" json:"serverName,omitempty"` + PeerCertificates *Certificates `protobuf:"bytes,8,opt,name=peerCertificates,proto3" json:"peerCertificates,omitempty"` + VerifiedChains []*Certificates `protobuf:"bytes,9,rep,name=verifiedChains,proto3" json:"verifiedChains,omitempty"` + SignedCertificateTimestamps [][]byte `protobuf:"bytes,10,rep,name=signedCertificateTimestamps,proto3" json:"signedCertificateTimestamps,omitempty"` + OcspResponse []byte `protobuf:"bytes,11,opt,name=ocspResponse,proto3" json:"ocspResponse,omitempty"` + TlsUnique []byte `protobuf:"bytes,12,opt,name=tlsUnique,proto3" json:"tlsUnique,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ConnectionState) Reset() { *m = ConnectionState{} } +func (m *ConnectionState) String() string { return proto.CompactTextString(m) } +func (*ConnectionState) ProtoMessage() {} +func (*ConnectionState) Descriptor() ([]byte, []int) { + return fileDescriptor_11b04836674e6f94, []int{4} +} + +func (m *ConnectionState) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ConnectionState.Unmarshal(m, b) +} +func (m *ConnectionState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ConnectionState.Marshal(b, m, deterministic) +} +func (m *ConnectionState) XXX_Merge(src proto.Message) { + xxx_messageInfo_ConnectionState.Merge(m, src) +} +func (m *ConnectionState) XXX_Size() int { + return xxx_messageInfo_ConnectionState.Size(m) +} +func (m *ConnectionState) XXX_DiscardUnknown() { + xxx_messageInfo_ConnectionState.DiscardUnknown(m) +} + +var xxx_messageInfo_ConnectionState proto.InternalMessageInfo + +func (m *ConnectionState) GetVersion() uint32 { + if m != nil { + return m.Version + } + return 0 +} + +func (m *ConnectionState) GetHandshakeComplete() bool { + if m != nil { + return m.HandshakeComplete + } + return false +} + +func (m *ConnectionState) GetDidResume() bool { + if m != nil { + return m.DidResume + } + return false +} + +func (m *ConnectionState) GetCipherSuite() uint32 { + if m != nil { + return m.CipherSuite + } + return 0 +} + +func (m *ConnectionState) GetNegotiatedProtocol() string { + if m != nil { + return m.NegotiatedProtocol + } + return "" +} + +func (m *ConnectionState) GetNegotiatedProtocolIsMutual() bool { + if m != nil { + return m.NegotiatedProtocolIsMutual + } + return false +} + +func (m *ConnectionState) GetServerName() string { + if m != nil { + return m.ServerName + } + return "" +} + +func (m *ConnectionState) GetPeerCertificates() *Certificates { + if m != nil { + return m.PeerCertificates + } + return nil +} + +func (m *ConnectionState) GetVerifiedChains() []*Certificates { + if m != nil { + return m.VerifiedChains + } + return nil +} + +func (m *ConnectionState) GetSignedCertificateTimestamps() [][]byte { + if m != nil { + return m.SignedCertificateTimestamps + } + return nil +} + +func (m *ConnectionState) GetOcspResponse() []byte { + if m != nil { + return m.OcspResponse + } + return nil +} + +func (m *ConnectionState) GetTlsUnique() []byte { + if m != nil { + return m.TlsUnique + } + return nil +} + +type Request struct { + Method string `protobuf:"bytes,1,opt,name=method,proto3" json:"method,omitempty"` + Url *URL `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"` + Proto string `protobuf:"bytes,3,opt,name=proto,proto3" json:"proto,omitempty"` + ProtoMajor int32 `protobuf:"varint,4,opt,name=protoMajor,proto3" json:"protoMajor,omitempty"` + ProtoMinor int32 `protobuf:"varint,5,opt,name=protoMinor,proto3" json:"protoMinor,omitempty"` + Header []*Element `protobuf:"bytes,6,rep,name=header,proto3" json:"header,omitempty"` + Body uint32 `protobuf:"varint,7,opt,name=body,proto3" json:"body,omitempty"` + ContentLength int64 `protobuf:"varint,8,opt,name=contentLength,proto3" json:"contentLength,omitempty"` + TransferEncoding []string `protobuf:"bytes,9,rep,name=transferEncoding,proto3" json:"transferEncoding,omitempty"` + Host string `protobuf:"bytes,10,opt,name=host,proto3" json:"host,omitempty"` + Form []*Element `protobuf:"bytes,11,rep,name=form,proto3" json:"form,omitempty"` + PostForm []*Element `protobuf:"bytes,12,rep,name=postForm,proto3" json:"postForm,omitempty"` + TrailerKeys []string `protobuf:"bytes,13,rep,name=trailerKeys,proto3" json:"trailerKeys,omitempty"` + RemoteAddr string `protobuf:"bytes,14,opt,name=remoteAddr,proto3" json:"remoteAddr,omitempty"` + RequestURI string `protobuf:"bytes,15,opt,name=requestURI,proto3" json:"requestURI,omitempty"` + Tls *ConnectionState `protobuf:"bytes,16,opt,name=tls,proto3" json:"tls,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Request) Reset() { *m = Request{} } +func (m *Request) String() string { return proto.CompactTextString(m) } +func (*Request) ProtoMessage() {} +func (*Request) Descriptor() ([]byte, []int) { + return fileDescriptor_11b04836674e6f94, []int{5} +} + +func (m *Request) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Request.Unmarshal(m, b) +} +func (m *Request) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Request.Marshal(b, m, deterministic) +} +func (m *Request) XXX_Merge(src proto.Message) { + xxx_messageInfo_Request.Merge(m, src) +} +func (m *Request) XXX_Size() int { + return xxx_messageInfo_Request.Size(m) +} +func (m *Request) XXX_DiscardUnknown() { + xxx_messageInfo_Request.DiscardUnknown(m) +} + +var xxx_messageInfo_Request proto.InternalMessageInfo + +func (m *Request) GetMethod() string { + if m != nil { + return m.Method + } + return "" +} + +func (m *Request) GetUrl() *URL { + if m != nil { + return m.Url + } + return nil +} + +func (m *Request) GetProto() string { + if m != nil { + return m.Proto + } + return "" +} + +func (m *Request) GetProtoMajor() int32 { + if m != nil { + return m.ProtoMajor + } + return 0 +} + +func (m *Request) GetProtoMinor() int32 { + if m != nil { + return m.ProtoMinor + } + return 0 +} + +func (m *Request) GetHeader() []*Element { + if m != nil { + return m.Header + } + return nil +} + +func (m *Request) GetBody() uint32 { + if m != nil { + return m.Body + } + return 0 +} + +func (m *Request) GetContentLength() int64 { + if m != nil { + return m.ContentLength + } + return 0 +} + +func (m *Request) GetTransferEncoding() []string { + if m != nil { + return m.TransferEncoding + } + return nil +} + +func (m *Request) GetHost() string { + if m != nil { + return m.Host + } + return "" +} + +func (m *Request) GetForm() []*Element { + if m != nil { + return m.Form + } + return nil +} + +func (m *Request) GetPostForm() []*Element { + if m != nil { + return m.PostForm + } + return nil +} + +func (m *Request) GetTrailerKeys() []string { + if m != nil { + return m.TrailerKeys + } + return nil +} + +func (m *Request) GetRemoteAddr() string { + if m != nil { + return m.RemoteAddr + } + return "" +} + +func (m *Request) GetRequestURI() string { + if m != nil { + return m.RequestURI + } + return "" +} + +func (m *Request) GetTls() *ConnectionState { + if m != nil { + return m.Tls + } + return nil +} + type HTTPRequest struct { - Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"` - Method string `protobuf:"bytes,2,opt,name=method,proto3" json:"method,omitempty"` - Headers []*Header `protobuf:"bytes,3,rep,name=headers,proto3" json:"headers,omitempty"` - Body []byte `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + ResponseWriter uint32 `protobuf:"varint,1,opt,name=responseWriter,proto3" json:"responseWriter,omitempty"` + Request *Request `protobuf:"bytes,2,opt,name=request,proto3" json:"request,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *HTTPRequest) Reset() { *m = HTTPRequest{} } func (m *HTTPRequest) String() string { return proto.CompactTextString(m) } func (*HTTPRequest) ProtoMessage() {} func (*HTTPRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11b04836674e6f94, []int{1} + return fileDescriptor_11b04836674e6f94, []int{6} } func (m *HTTPRequest) XXX_Unmarshal(b []byte) error { @@ -106,48 +587,31 @@ func (m *HTTPRequest) XXX_DiscardUnknown() { var xxx_messageInfo_HTTPRequest proto.InternalMessageInfo -func (m *HTTPRequest) GetUrl() string { +func (m *HTTPRequest) GetResponseWriter() uint32 { if m != nil { - return m.Url + return m.ResponseWriter } - return "" + return 0 } -func (m *HTTPRequest) GetMethod() string { +func (m *HTTPRequest) GetRequest() *Request { if m != nil { - return m.Method - } - return "" -} - -func (m *HTTPRequest) GetHeaders() []*Header { - if m != nil { - return m.Headers - } - return nil -} - -func (m *HTTPRequest) GetBody() []byte { - if m != nil { - return m.Body + return m.Request } return nil } type HTTPResponse struct { - Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` - Headers []*Header `protobuf:"bytes,2,rep,name=headers,proto3" json:"headers,omitempty"` - Body []byte `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *HTTPResponse) Reset() { *m = HTTPResponse{} } func (m *HTTPResponse) String() string { return proto.CompactTextString(m) } func (*HTTPResponse) ProtoMessage() {} func (*HTTPResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11b04836674e6f94, []int{2} + return fileDescriptor_11b04836674e6f94, []int{7} } func (m *HTTPResponse) XXX_Unmarshal(b []byte) error { @@ -168,29 +632,13 @@ func (m *HTTPResponse) XXX_DiscardUnknown() { var xxx_messageInfo_HTTPResponse proto.InternalMessageInfo -func (m *HTTPResponse) GetCode() int32 { - if m != nil { - return m.Code - } - return 0 -} - -func (m *HTTPResponse) GetHeaders() []*Header { - if m != nil { - return m.Headers - } - return nil -} - -func (m *HTTPResponse) GetBody() []byte { - if m != nil { - return m.Body - } - return nil -} - func init() { - proto.RegisterType((*Header)(nil), "proto.Header") + proto.RegisterType((*Userinfo)(nil), "proto.Userinfo") + proto.RegisterType((*URL)(nil), "proto.URL") + proto.RegisterType((*Element)(nil), "proto.Element") + proto.RegisterType((*Certificates)(nil), "proto.Certificates") + proto.RegisterType((*ConnectionState)(nil), "proto.ConnectionState") + proto.RegisterType((*Request)(nil), "proto.Request") proto.RegisterType((*HTTPRequest)(nil), "proto.HTTPRequest") proto.RegisterType((*HTTPResponse)(nil), "proto.HTTPResponse") } @@ -198,22 +646,58 @@ func init() { func init() { proto.RegisterFile("http.proto", fileDescriptor_11b04836674e6f94) } var fileDescriptor_11b04836674e6f94 = []byte{ - // 225 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x8f, 0x4f, 0x4b, 0x03, 0x31, - 0x14, 0xc4, 0xd9, 0xcd, 0x76, 0xa5, 0xaf, 0x15, 0xe4, 0x09, 0x12, 0x3c, 0x85, 0xbd, 0x98, 0x53, - 0xc1, 0xf5, 0xe4, 0x37, 0xd8, 0xa3, 0x84, 0xde, 0x65, 0x6b, 0x1e, 0x2c, 0x18, 0x9b, 0x35, 0x7f, - 0x84, 0x7e, 0x7b, 0x49, 0xd2, 0xa5, 0x7a, 0xeb, 0x29, 0x33, 0x93, 0x0c, 0xbf, 0x09, 0xc0, 0x14, - 0xc2, 0xbc, 0x9b, 0x9d, 0x0d, 0x16, 0x57, 0xf9, 0xe8, 0x7a, 0x68, 0x07, 0x1a, 0x35, 0x39, 0xbc, - 0x03, 0xf6, 0x49, 0x27, 0x5e, 0x89, 0x4a, 0xae, 0x55, 0x92, 0xf8, 0x00, 0xed, 0xcf, 0x68, 0x22, - 0x79, 0x5e, 0x0b, 0x26, 0xd7, 0xea, 0xec, 0xba, 0x00, 0x9b, 0x61, 0xbf, 0x7f, 0x53, 0xf4, 0x1d, - 0xc9, 0x87, 0x54, 0x8c, 0xce, 0x2c, 0xc5, 0xe8, 0x4c, 0x2a, 0x7e, 0x51, 0x98, 0xac, 0xe6, 0x75, - 0x0e, 0xcf, 0x0e, 0x9f, 0xe0, 0x66, 0xca, 0x30, 0xcf, 0x99, 0x60, 0x72, 0xd3, 0xdf, 0x96, 0x31, - 0xbb, 0x32, 0x41, 0x2d, 0xb7, 0x88, 0xd0, 0x1c, 0xac, 0x3e, 0xf1, 0x46, 0x54, 0x72, 0xab, 0xb2, - 0xee, 0xde, 0x61, 0x5b, 0xa8, 0x7e, 0xb6, 0x47, 0x4f, 0xe9, 0xcd, 0x87, 0xd5, 0x94, 0xb9, 0x2b, - 0x95, 0xf5, 0x5f, 0x40, 0x7d, 0x15, 0x80, 0x5d, 0x00, 0xfd, 0x2b, 0x34, 0x09, 0x80, 0xcf, 0xd0, - 0x0e, 0xe3, 0x51, 0x1b, 0x42, 0x5c, 0xda, 0x97, 0xdf, 0x3e, 0xde, 0xff, 0xcb, 0xca, 0x96, 0x43, - 0x9b, 0xb3, 0x97, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xbf, 0x5a, 0x2a, 0xb5, 0x61, 0x01, 0x00, - 0x00, + // 816 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x54, 0xdb, 0x6e, 0x1b, 0x37, + 0x10, 0x85, 0xb2, 0xb2, 0x2e, 0xa3, 0x8b, 0x5d, 0xa6, 0x08, 0x08, 0x37, 0x28, 0x84, 0x6d, 0x11, + 0x08, 0x41, 0x61, 0xa0, 0xce, 0x53, 0x51, 0xa0, 0x17, 0x18, 0x29, 0x12, 0xd4, 0x29, 0x5c, 0xda, + 0x46, 0x1f, 0x0b, 0x66, 0x77, 0xa4, 0x65, 0xb3, 0x4b, 0x6e, 0x48, 0xae, 0x0c, 0x7f, 0x47, 0x3f, + 0xa3, 0xbf, 0xd7, 0x0f, 0x28, 0x78, 0x59, 0x69, 0x15, 0xb9, 0x7e, 0xda, 0x99, 0x73, 0x86, 0xcb, + 0x99, 0x39, 0x33, 0x04, 0x28, 0xac, 0xad, 0xcf, 0x6a, 0xad, 0xac, 0x22, 0x47, 0xfe, 0x93, 0xe6, + 0x30, 0xba, 0x35, 0xa8, 0x85, 0x5c, 0x29, 0x72, 0x0a, 0xa3, 0xc6, 0xa0, 0x96, 0xbc, 0x42, 0xda, + 0x5b, 0xf4, 0x96, 0x63, 0xb6, 0xf5, 0x1d, 0x57, 0x73, 0x63, 0xee, 0x94, 0xce, 0xe9, 0x93, 0xc0, + 0xb5, 0x3e, 0x59, 0xc0, 0xa4, 0xb5, 0xaf, 0xd1, 0xd2, 0x64, 0xd1, 0x5b, 0x8e, 0x58, 0x17, 0x4a, + 0xff, 0xed, 0x41, 0x72, 0xcb, 0x2e, 0xc9, 0x33, 0x18, 0x98, 0xac, 0xc0, 0xed, 0xff, 0xa3, 0xe7, + 0x70, 0x55, 0xf3, 0x8f, 0x0d, 0xc6, 0x7f, 0x47, 0x8f, 0x7c, 0x05, 0x7d, 0x97, 0x81, 0xff, 0xe5, + 0xe4, 0xfc, 0x38, 0xa4, 0x7e, 0xd6, 0x26, 0xcc, 0x3c, 0x49, 0x08, 0xf4, 0x0b, 0x65, 0x2c, 0xed, + 0xfb, 0xa3, 0xde, 0x76, 0x58, 0xcd, 0x6d, 0x41, 0x8f, 0x02, 0xe6, 0x6c, 0x42, 0x61, 0xa8, 0xf9, + 0xdd, 0x95, 0x83, 0x07, 0x1e, 0x6e, 0x5d, 0xf2, 0x25, 0xc0, 0x4a, 0xe9, 0x0c, 0x7f, 0x6f, 0x50, + 0xdf, 0xd3, 0xa1, 0xcf, 0xbf, 0x83, 0xb8, 0xe2, 0x35, 0xbf, 0x0b, 0xec, 0x28, 0x14, 0xdf, 0xfa, + 0x8e, 0x5b, 0x69, 0xbe, 0xae, 0x50, 0x5a, 0x3a, 0x0e, 0x5c, 0xeb, 0xa7, 0xaf, 0x60, 0xf8, 0xba, + 0x44, 0x67, 0x92, 0x13, 0x48, 0x3e, 0xe0, 0x7d, 0x2c, 0xdb, 0x99, 0xae, 0xe6, 0x0d, 0x2f, 0x1b, + 0x34, 0xf4, 0xc9, 0x22, 0x71, 0x35, 0x07, 0x2f, 0x4d, 0x61, 0x7a, 0x81, 0xda, 0x8a, 0x95, 0xc8, + 0xb8, 0x45, 0xe3, 0x4a, 0xc9, 0x50, 0x5b, 0xda, 0x5b, 0x24, 0xcb, 0x29, 0xf3, 0x76, 0xfa, 0x4f, + 0x1f, 0x8e, 0x2f, 0x94, 0x94, 0x98, 0x59, 0xa1, 0xe4, 0xb5, 0xe5, 0x16, 0x5d, 0x79, 0x1b, 0xd4, + 0x46, 0x28, 0xe9, 0x6f, 0x99, 0xb1, 0xd6, 0x25, 0xdf, 0xc0, 0x67, 0x05, 0x97, 0xb9, 0x29, 0xf8, + 0x07, 0xbc, 0x50, 0x55, 0x5d, 0xa2, 0x0d, 0x8d, 0x1e, 0xb1, 0x43, 0x82, 0x3c, 0x87, 0x71, 0x2e, + 0x72, 0x86, 0xa6, 0xa9, 0x30, 0x6a, 0xb9, 0x03, 0x9c, 0xd6, 0x99, 0xa8, 0x0b, 0xd4, 0xd7, 0x8d, + 0xb0, 0xe8, 0x7b, 0x3e, 0x63, 0x5d, 0x88, 0x9c, 0x01, 0x91, 0xb8, 0x56, 0x56, 0x70, 0x8b, 0xf9, + 0x95, 0x13, 0x2c, 0x53, 0x65, 0x14, 0xe2, 0x01, 0x86, 0xfc, 0x00, 0xa7, 0x87, 0xe8, 0x5b, 0xf3, + 0xae, 0xb1, 0x0d, 0x2f, 0xbd, 0x52, 0x23, 0xf6, 0x48, 0x84, 0x13, 0xcf, 0xa0, 0xde, 0xa0, 0xfe, + 0xcd, 0xcd, 0xed, 0xd0, 0xdf, 0xd3, 0x41, 0xc8, 0x8f, 0x70, 0x52, 0x23, 0xea, 0x6e, 0x4f, 0xbd, + 0x88, 0x93, 0xf3, 0xa7, 0x71, 0x9e, 0xba, 0x14, 0x3b, 0x08, 0x26, 0xdf, 0xc3, 0x7c, 0x83, 0x5a, + 0xac, 0x04, 0xe6, 0x17, 0x05, 0x17, 0xd2, 0xd0, 0xf1, 0x22, 0xf9, 0xbf, 0xe3, 0x9f, 0x84, 0x92, + 0x9f, 0xe0, 0x0b, 0x23, 0xd6, 0x12, 0xf3, 0x4e, 0xd4, 0x8d, 0xa8, 0xd0, 0x58, 0x5e, 0xd5, 0x86, + 0x82, 0x17, 0xf5, 0xb1, 0x10, 0x92, 0xc2, 0x54, 0x65, 0xa6, 0x66, 0x68, 0x6a, 0x25, 0x0d, 0xd2, + 0xc9, 0xa2, 0xb7, 0x9c, 0xb2, 0x3d, 0xcc, 0x69, 0x66, 0x4b, 0x73, 0x2b, 0x85, 0x5b, 0xa1, 0xa9, + 0x0f, 0xd8, 0x01, 0xe9, 0xdf, 0x7d, 0x18, 0x32, 0xfc, 0xd8, 0xa0, 0xb1, 0x6e, 0xea, 0x2a, 0xb4, + 0x85, 0xca, 0xdb, 0x0d, 0x0c, 0x1e, 0x79, 0x0e, 0x49, 0xa3, 0x4b, 0x3f, 0x15, 0x93, 0x73, 0x68, + 0x17, 0x8d, 0x5d, 0x32, 0x07, 0x93, 0xcf, 0x21, 0x3c, 0x17, 0x7e, 0x1e, 0xc6, 0x2c, 0x38, 0xae, + 0xf3, 0xde, 0x78, 0xc7, 0xff, 0x52, 0xda, 0x8f, 0xc2, 0x11, 0xeb, 0x20, 0x3b, 0x5e, 0x48, 0xa5, + 0xfd, 0x04, 0x6c, 0x79, 0x87, 0x90, 0x17, 0x30, 0x28, 0x90, 0xe7, 0xa8, 0xe9, 0xc0, 0x37, 0x74, + 0x1e, 0xaf, 0x8d, 0x3b, 0xc3, 0x22, 0xeb, 0x36, 0xe0, 0xbd, 0xca, 0xc3, 0x62, 0xce, 0x98, 0xb7, + 0xc9, 0xd7, 0x30, 0xcb, 0x94, 0xb4, 0x28, 0xed, 0x25, 0xca, 0xb5, 0x2d, 0xbc, 0xa4, 0x09, 0xdb, + 0x07, 0xc9, 0x4b, 0x38, 0xb1, 0x9a, 0x4b, 0xb3, 0x42, 0xfd, 0x5a, 0x66, 0x2a, 0x17, 0x72, 0xed, + 0xc5, 0x1b, 0xb3, 0x03, 0x7c, 0xfb, 0x8c, 0x40, 0xe7, 0x19, 0x49, 0xa1, 0xbf, 0x52, 0xba, 0xa2, + 0x93, 0x07, 0xf3, 0xf3, 0x1c, 0x79, 0x09, 0xa3, 0x5a, 0x19, 0xfb, 0x8b, 0x8b, 0x9b, 0x3e, 0x18, + 0xb7, 0xe5, 0xdd, 0xf6, 0x58, 0xcd, 0x45, 0x89, 0xfa, 0x57, 0xbc, 0x37, 0x74, 0xe6, 0x53, 0xe9, + 0x42, 0xae, 0x67, 0x1a, 0x2b, 0x65, 0xf1, 0xe7, 0x3c, 0xd7, 0x74, 0x1e, 0xa6, 0x79, 0x87, 0x04, + 0xde, 0x4b, 0x79, 0xcb, 0xde, 0xd2, 0xe3, 0x96, 0x6f, 0x11, 0xb2, 0x84, 0xc4, 0x96, 0x86, 0x9e, + 0x78, 0x1d, 0x9f, 0xb5, 0x13, 0xba, 0xff, 0x54, 0x30, 0x17, 0x92, 0xfe, 0x09, 0x93, 0x37, 0x37, + 0x37, 0x57, 0xed, 0x60, 0xbc, 0x80, 0xb9, 0x8e, 0xe3, 0xf4, 0x87, 0x16, 0x16, 0x75, 0x7c, 0x45, + 0x3e, 0x41, 0xc9, 0x12, 0x86, 0xf1, 0xba, 0x38, 0x2c, 0x6d, 0xb5, 0xf1, 0x47, 0xac, 0xa5, 0xd3, + 0x39, 0x4c, 0xc3, 0x05, 0xe1, 0xfc, 0xf9, 0x77, 0xd0, 0x77, 0x3e, 0xf9, 0x16, 0x06, 0x6f, 0xb8, + 0xcc, 0x4b, 0x24, 0x24, 0x1e, 0xed, 0xe4, 0x71, 0xfa, 0x74, 0x0f, 0x0b, 0x47, 0xdf, 0x0f, 0x3c, + 0xf6, 0xea, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xbf, 0x29, 0xb2, 0xd4, 0xc1, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/vms/rpcchainvm/ghttp/proto/http.proto b/vms/rpcchainvm/ghttp/proto/http.proto index ec23597..f5e9c71 100644 --- a/vms/rpcchainvm/ghttp/proto/http.proto +++ b/vms/rpcchainvm/ghttp/proto/http.proto @@ -1,24 +1,75 @@ syntax = "proto3"; package proto; -message Header { + +message Userinfo { + string username = 1; + string password = 2; + bool passwordSet = 3; +} + +message URL { + string scheme = 1; + string opaque = 2; + Userinfo user = 3; + string host = 4; + string path = 5; + string rawPath = 6; + bool forceQuery = 7; + string rawQuery = 8; + string fragment = 9; +} + +message Element { string key = 1; repeated string values = 2; } -message HTTPRequest { - string url = 1; - string method = 2; - repeated Header headers = 3; - bytes body = 4; +message Certificates { + repeated bytes cert = 1; } -message HTTPResponse { - int32 code = 1; - repeated Header headers = 2; - bytes body = 3; +message ConnectionState { + uint32 version = 1; + bool handshakeComplete = 2; + bool didResume = 3; + uint32 cipherSuite = 4; + string negotiatedProtocol = 5; + bool negotiatedProtocolIsMutual = 6; + string serverName = 7; + Certificates peerCertificates = 8; + repeated Certificates verifiedChains = 9; + repeated bytes signedCertificateTimestamps = 10; + bytes ocspResponse = 11; + bytes tlsUnique = 12; } +message Request { + string method = 1; + URL url = 2; + string proto = 3; + int32 protoMajor = 4; + int32 protoMinor = 5; + repeated Element header = 6; + uint32 body = 7; // server ID + int64 contentLength = 8; + repeated string transferEncoding = 9; + string host = 10; + repeated Element form = 11; + repeated Element postForm = 12; + repeated string trailerKeys = 13; + string remoteAddr = 14; + string requestURI = 15; + ConnectionState tls = 16; +} + +message HTTPRequest { + uint32 responseWriter = 1; // server ID + Request request = 2; +} + +message HTTPResponse {} + service HTTP { rpc Handle(HTTPRequest) returns (HTTPResponse); } \ No newline at end of file diff --git a/vms/rpcchainvm/vm_client.go b/vms/rpcchainvm/vm_client.go index 45b727d..098241e 100644 --- a/vms/rpcchainvm/vm_client.go +++ b/vms/rpcchainvm/vm_client.go @@ -172,7 +172,7 @@ func (vm *VMClient) CreateHandlers() map[string]*common.HTTPHandler { vm.conns = append(vm.conns, conn) handlers[handler.Prefix] = &common.HTTPHandler{ LockOptions: common.LockOption(handler.LockOptions), - Handler: ghttp.NewClient(httpproto.NewHTTPClient(conn)), + Handler: ghttp.NewClient(httpproto.NewHTTPClient(conn), vm.broker), } } return handlers diff --git a/vms/rpcchainvm/vm_server.go b/vms/rpcchainvm/vm_server.go index 217a1f2..e83a957 100644 --- a/vms/rpcchainvm/vm_server.go +++ b/vms/rpcchainvm/vm_server.go @@ -127,7 +127,7 @@ func (vm *VMServer) CreateHandlers(_ context.Context, req *vmproto.CreateHandler vm.servers = append(vm.servers, server) } - httpproto.RegisterHTTPServer(server, ghttp.NewServer(handler.Handler)) + httpproto.RegisterHTTPServer(server, ghttp.NewServer(handler.Handler, vm.broker)) return server }) From aebb1164dc238456517adabd3a00bfa06d8f4ae6 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Fri, 17 Apr 2020 03:04:35 -0400 Subject: [PATCH 16/61] Removed warning --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 645dbaf..c133936 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ sudo apt-get install libssl-dev libuv1-dev cmake make curl g++ Clone the Gecko repository: ```sh -go get github.com/ava-labs/gecko +go get -v -d github.com/ava-labs/gecko/... cd $GOPATH/src/github.com/ava-labs/gecko ``` From f40ea1ef45f9e0300783de5830ff660363ba4b48 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Fri, 17 Apr 2020 03:51:14 -0400 Subject: [PATCH 17/61] Changed default values to cascade --- main/params.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main/params.go b/main/params.go index b17b5cd..0438a60 100644 --- a/main/params.go +++ b/main/params.go @@ -35,6 +35,14 @@ var ( // GetIPs returns the default IPs for each network func GetIPs(networkID uint32) []string { switch networkID { + case genesis.CascadeID: + return []string{ + "3.227.207.132:21001", + "34.207.133.167:21001", + "107.23.241.199:21001", + "54.197.215.186:21001", + "18.234.153.22:21001", + } default: return nil } @@ -55,7 +63,7 @@ func init() { fs := flag.NewFlagSet("gecko", flag.ContinueOnError) // NetworkID: - networkName := fs.String("network-id", genesis.LocalName, "Network ID this node will connect to") + networkName := fs.String("network-id", genesis.CascadeName, "Network ID this node will connect to") // Ava fees: fs.Uint64Var(&Config.AvaTxFee, "ava-tx-fee", 0, "Ava transaction fee, in $nAva") From d4996b5a3ab1d4bb3a92220c03cba8c4c0a413e9 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Fri, 17 Apr 2020 04:20:24 -0400 Subject: [PATCH 18/61] Reduced log level of missing parent block --- vms/platformvm/common_blocks.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vms/platformvm/common_blocks.go b/vms/platformvm/common_blocks.go index 9d143f8..0d05911 100644 --- a/vms/platformvm/common_blocks.go +++ b/vms/platformvm/common_blocks.go @@ -174,7 +174,7 @@ func (cb *CommonBlock) parentBlock() Block { parentID := cb.ParentID() parent, err := cb.vm.getBlock(parentID) if err != nil { - cb.vm.Ctx.Log.Warn("could not get parent (ID %s) of block %s", parentID, cb.ID()) + cb.vm.Ctx.Log.Debug("could not get parent (ID %s) of block %s", parentID, cb.ID()) return nil } cb.parent = parent From 8b86d158505c8687aa426772d6d990982486855c Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Fri, 17 Apr 2020 09:47:19 -0400 Subject: [PATCH 19/61] resolve proto conflicts --- database/rpcdb/db_client.go | 34 +-- database/rpcdb/db_server.go | 50 ++-- database/rpcdb/db_test.go | 6 +- .../db.pb.go => rpcdbproto/rpcdb.pb.go} | 243 +++++++++--------- .../db.proto => rpcdbproto/rpcdb.proto} | 2 +- vms/rpcchainvm/ghttp/gconn/conn_client.go | 18 +- vms/rpcchainvm/ghttp/gconn/conn_server.go | 26 +- .../conn.pb.go => gconnproto/gconn.pb.go} | 131 +++++----- .../conn.proto => gconnproto/gconn.proto} | 2 +- .../http.pb.go => ghttpproto/ghttp.pb.go} | 153 +++++------ .../http.proto => ghttpproto/ghttp.proto} | 3 +- .../greadcloser.pb.go} | 64 ++--- .../greadcloser.proto} | 2 +- .../ghttp/greadcloser/reader_client.go | 10 +- .../ghttp/greadcloser/reader_server.go | 10 +- .../greader.pb.go} | 48 ++-- .../greader.proto} | 2 +- vms/rpcchainvm/ghttp/greader/reader_client.go | 8 +- vms/rpcchainvm/ghttp/greader/reader_server.go | 6 +- .../gresponsewriter.pb.go} | 119 ++++----- .../gresponsewriter.proto} | 3 +- .../ghttp/gresponsewriter/writer_client.go | 35 ++- .../ghttp/gresponsewriter/writer_server.go | 40 +-- .../gwriter.pb.go} | 48 ++-- .../gwriter.proto} | 2 +- vms/rpcchainvm/ghttp/gwriter/writer_client.go | 8 +- vms/rpcchainvm/ghttp/gwriter/writer_server.go | 6 +- vms/rpcchainvm/ghttp/http_client.go | 43 ++-- vms/rpcchainvm/ghttp/http_server.go | 15 +- vms/rpcchainvm/messenger/messenger_client.go | 10 +- vms/rpcchainvm/messenger/messenger_server.go | 6 +- .../{proto => messengerproto}/messenger.pb.go | 28 +- .../{proto => messengerproto}/messenger.proto | 2 +- vms/rpcchainvm/vm.go | 6 +- vms/rpcchainvm/vm_client.go | 15 +- vms/rpcchainvm/vm_server.go | 15 +- vms/rpcchainvm/{proto => vmproto}/vm.pb.go | 174 ++++++------- vms/rpcchainvm/{proto => vmproto}/vm.proto | 2 +- 38 files changed, 698 insertions(+), 697 deletions(-) rename database/rpcdb/{proto/db.pb.go => rpcdbproto/rpcdb.pb.go} (84%) rename database/rpcdb/{proto/db.proto => rpcdbproto/rpcdb.proto} (98%) rename vms/rpcchainvm/ghttp/gconn/{proto/conn.pb.go => gconnproto/gconn.pb.go} (84%) rename vms/rpcchainvm/ghttp/gconn/{proto/conn.proto => gconnproto/gconn.proto} (98%) rename vms/rpcchainvm/ghttp/{proto/http.pb.go => ghttpproto/ghttp.pb.go} (76%) rename vms/rpcchainvm/ghttp/{proto/http.proto => ghttpproto/ghttp.proto} (98%) rename vms/rpcchainvm/ghttp/greadcloser/{proto/reader.pb.go => greadcloserproto/greadcloser.pb.go} (79%) rename vms/rpcchainvm/ghttp/greadcloser/{proto/reader.proto => greadcloserproto/greadcloser.proto} (92%) rename vms/rpcchainvm/ghttp/greader/{proto/reader.pb.go => greaderproto/greader.pb.go} (77%) rename vms/rpcchainvm/ghttp/greader/{proto/reader.proto => greaderproto/greader.proto} (90%) rename vms/rpcchainvm/ghttp/gresponsewriter/{proto/writer.pb.go => gresponsewriterproto/gresponsewriter.pb.go} (80%) rename vms/rpcchainvm/ghttp/gresponsewriter/{proto/writer.proto => gresponsewriterproto/gresponsewriter.proto} (92%) rename vms/rpcchainvm/ghttp/gwriter/{proto/writer.pb.go => gwriterproto/gwriter.pb.go} (78%) rename vms/rpcchainvm/ghttp/gwriter/{proto/writer.proto => gwriterproto/gwriter.proto} (91%) rename vms/rpcchainvm/messenger/{proto => messengerproto}/messenger.pb.go (85%) rename vms/rpcchainvm/messenger/{proto => messengerproto}/messenger.proto (87%) rename vms/rpcchainvm/{proto => vmproto}/vm.pb.go (87%) rename vms/rpcchainvm/{proto => vmproto}/vm.proto (99%) diff --git a/database/rpcdb/db_client.go b/database/rpcdb/db_client.go index 8d23049..136121b 100644 --- a/database/rpcdb/db_client.go +++ b/database/rpcdb/db_client.go @@ -10,7 +10,7 @@ import ( "github.com/ava-labs/gecko/database" "github.com/ava-labs/gecko/database/nodb" - "github.com/ava-labs/gecko/database/rpcdb/proto" + "github.com/ava-labs/gecko/database/rpcdb/rpcdbproto" ) var ( @@ -19,16 +19,16 @@ var ( ) // DatabaseClient is an implementation of database that talks over RPC. -type DatabaseClient struct{ client proto.DatabaseClient } +type DatabaseClient struct{ client rpcdbproto.DatabaseClient } // NewClient returns a database instance connected to a remote database instance -func NewClient(client proto.DatabaseClient) *DatabaseClient { +func NewClient(client rpcdbproto.DatabaseClient) *DatabaseClient { return &DatabaseClient{client: client} } // Has returns false, nil func (db *DatabaseClient) Has(key []byte) (bool, error) { - resp, err := db.client.Has(context.Background(), &proto.HasRequest{ + resp, err := db.client.Has(context.Background(), &rpcdbproto.HasRequest{ Key: key, }) if err != nil { @@ -39,7 +39,7 @@ func (db *DatabaseClient) Has(key []byte) (bool, error) { // Get returns nil, error func (db *DatabaseClient) Get(key []byte) ([]byte, error) { - resp, err := db.client.Get(context.Background(), &proto.GetRequest{ + resp, err := db.client.Get(context.Background(), &rpcdbproto.GetRequest{ Key: key, }) if err != nil { @@ -50,7 +50,7 @@ func (db *DatabaseClient) Get(key []byte) ([]byte, error) { // Put returns nil func (db *DatabaseClient) Put(key, value []byte) error { - _, err := db.client.Put(context.Background(), &proto.PutRequest{ + _, err := db.client.Put(context.Background(), &rpcdbproto.PutRequest{ Key: key, Value: value, }) @@ -59,7 +59,7 @@ func (db *DatabaseClient) Put(key, value []byte) error { // Delete returns nil func (db *DatabaseClient) Delete(key []byte) error { - _, err := db.client.Delete(context.Background(), &proto.DeleteRequest{ + _, err := db.client.Delete(context.Background(), &rpcdbproto.DeleteRequest{ Key: key, }) return updateError(err) @@ -85,7 +85,7 @@ func (db *DatabaseClient) NewIteratorWithPrefix(prefix []byte) database.Iterator // NewIteratorWithStartAndPrefix returns a new empty iterator func (db *DatabaseClient) NewIteratorWithStartAndPrefix(start, prefix []byte) database.Iterator { - resp, err := db.client.NewIteratorWithStartAndPrefix(context.Background(), &proto.NewIteratorWithStartAndPrefixRequest{ + resp, err := db.client.NewIteratorWithStartAndPrefix(context.Background(), &rpcdbproto.NewIteratorWithStartAndPrefixRequest{ Start: start, Prefix: prefix, }) @@ -100,7 +100,7 @@ func (db *DatabaseClient) NewIteratorWithStartAndPrefix(start, prefix []byte) da // Stat returns an error func (db *DatabaseClient) Stat(property string) (string, error) { - resp, err := db.client.Stat(context.Background(), &proto.StatRequest{ + resp, err := db.client.Stat(context.Background(), &rpcdbproto.StatRequest{ Property: property, }) if err != nil { @@ -111,7 +111,7 @@ func (db *DatabaseClient) Stat(property string) (string, error) { // Compact returns nil func (db *DatabaseClient) Compact(start, limit []byte) error { - _, err := db.client.Compact(context.Background(), &proto.CompactRequest{ + _, err := db.client.Compact(context.Background(), &rpcdbproto.CompactRequest{ Start: start, Limit: limit, }) @@ -120,7 +120,7 @@ func (db *DatabaseClient) Compact(start, limit []byte) error { // Close returns nil func (db *DatabaseClient) Close() error { - _, err := db.client.Close(context.Background(), &proto.CloseRequest{}) + _, err := db.client.Close(context.Background(), &rpcdbproto.CloseRequest{}) return updateError(err) } @@ -151,7 +151,7 @@ func (b *batch) Delete(key []byte) error { func (b *batch) ValueSize() int { return b.size } func (b *batch) Write() error { - request := &proto.WriteBatchRequest{} + request := &rpcdbproto.WriteBatchRequest{} keySet := make(map[string]struct{}, len(b.writes)) for i := len(b.writes) - 1; i >= 0; i-- { @@ -163,11 +163,11 @@ func (b *batch) Write() error { keySet[key] = struct{}{} if kv.delete { - request.Deletes = append(request.Deletes, &proto.DeleteRequest{ + request.Deletes = append(request.Deletes, &rpcdbproto.DeleteRequest{ Key: kv.key, }) } else { - request.Puts = append(request.Puts, &proto.PutRequest{ + request.Puts = append(request.Puts, &rpcdbproto.PutRequest{ Key: kv.key, Value: kv.value, }) @@ -208,7 +208,7 @@ type iterator struct { // Next returns false func (it *iterator) Next() bool { - resp, err := it.db.client.IteratorNext(context.Background(), &proto.IteratorNextRequest{ + resp, err := it.db.client.IteratorNext(context.Background(), &rpcdbproto.IteratorNextRequest{ Id: it.id, }) if err != nil { @@ -226,7 +226,7 @@ func (it *iterator) Error() error { return it.err } - _, err := it.db.client.IteratorError(context.Background(), &proto.IteratorErrorRequest{ + _, err := it.db.client.IteratorError(context.Background(), &rpcdbproto.IteratorErrorRequest{ Id: it.id, }) it.err = updateError(err) @@ -241,7 +241,7 @@ func (it *iterator) Value() []byte { return it.value } // Release does nothing func (it *iterator) Release() { - it.db.client.IteratorRelease(context.Background(), &proto.IteratorReleaseRequest{ + it.db.client.IteratorRelease(context.Background(), &rpcdbproto.IteratorReleaseRequest{ Id: it.id, }) } diff --git a/database/rpcdb/db_server.go b/database/rpcdb/db_server.go index 5abc3be..fe4b47a 100644 --- a/database/rpcdb/db_server.go +++ b/database/rpcdb/db_server.go @@ -9,7 +9,7 @@ import ( "golang.org/x/net/context" "github.com/ava-labs/gecko/database" - "github.com/ava-labs/gecko/database/rpcdb/proto" + "github.com/ava-labs/gecko/database/rpcdb/rpcdbproto" ) var ( @@ -35,54 +35,54 @@ func NewServer(db database.Database) *DatabaseServer { } // Has ... -func (db *DatabaseServer) Has(_ context.Context, req *proto.HasRequest) (*proto.HasResponse, error) { +func (db *DatabaseServer) Has(_ context.Context, req *rpcdbproto.HasRequest) (*rpcdbproto.HasResponse, error) { has, err := db.db.Has(req.Key) if err != nil { return nil, err } - return &proto.HasResponse{Has: has}, nil + return &rpcdbproto.HasResponse{Has: has}, nil } // Get ... -func (db *DatabaseServer) Get(_ context.Context, req *proto.GetRequest) (*proto.GetResponse, error) { +func (db *DatabaseServer) Get(_ context.Context, req *rpcdbproto.GetRequest) (*rpcdbproto.GetResponse, error) { value, err := db.db.Get(req.Key) if err != nil { return nil, err } - return &proto.GetResponse{Value: value}, nil + return &rpcdbproto.GetResponse{Value: value}, nil } // Put ... -func (db *DatabaseServer) Put(_ context.Context, req *proto.PutRequest) (*proto.PutResponse, error) { - return &proto.PutResponse{}, db.db.Put(req.Key, req.Value) +func (db *DatabaseServer) Put(_ context.Context, req *rpcdbproto.PutRequest) (*rpcdbproto.PutResponse, error) { + return &rpcdbproto.PutResponse{}, db.db.Put(req.Key, req.Value) } // Delete ... -func (db *DatabaseServer) Delete(_ context.Context, req *proto.DeleteRequest) (*proto.DeleteResponse, error) { - return &proto.DeleteResponse{}, db.db.Delete(req.Key) +func (db *DatabaseServer) Delete(_ context.Context, req *rpcdbproto.DeleteRequest) (*rpcdbproto.DeleteResponse, error) { + return &rpcdbproto.DeleteResponse{}, db.db.Delete(req.Key) } // Stat ... -func (db *DatabaseServer) Stat(_ context.Context, req *proto.StatRequest) (*proto.StatResponse, error) { +func (db *DatabaseServer) Stat(_ context.Context, req *rpcdbproto.StatRequest) (*rpcdbproto.StatResponse, error) { stat, err := db.db.Stat(req.Property) if err != nil { return nil, err } - return &proto.StatResponse{Stat: stat}, nil + return &rpcdbproto.StatResponse{Stat: stat}, nil } // Compact ... -func (db *DatabaseServer) Compact(_ context.Context, req *proto.CompactRequest) (*proto.CompactResponse, error) { - return &proto.CompactResponse{}, db.db.Compact(req.Start, req.Limit) +func (db *DatabaseServer) Compact(_ context.Context, req *rpcdbproto.CompactRequest) (*rpcdbproto.CompactResponse, error) { + return &rpcdbproto.CompactResponse{}, db.db.Compact(req.Start, req.Limit) } // Close ... -func (db *DatabaseServer) Close(_ context.Context, _ *proto.CloseRequest) (*proto.CloseResponse, error) { - return &proto.CloseResponse{}, db.db.Close() +func (db *DatabaseServer) Close(_ context.Context, _ *rpcdbproto.CloseRequest) (*rpcdbproto.CloseResponse, error) { + return &rpcdbproto.CloseResponse{}, db.db.Close() } // WriteBatch ... -func (db *DatabaseServer) WriteBatch(_ context.Context, req *proto.WriteBatchRequest) (*proto.WriteBatchResponse, error) { +func (db *DatabaseServer) WriteBatch(_ context.Context, req *rpcdbproto.WriteBatchRequest) (*rpcdbproto.WriteBatchResponse, error) { db.batch.Reset() for _, put := range req.Puts { @@ -97,26 +97,26 @@ func (db *DatabaseServer) WriteBatch(_ context.Context, req *proto.WriteBatchReq } } - return &proto.WriteBatchResponse{}, db.batch.Write() + return &rpcdbproto.WriteBatchResponse{}, db.batch.Write() } // NewIteratorWithStartAndPrefix ... -func (db *DatabaseServer) NewIteratorWithStartAndPrefix(_ context.Context, req *proto.NewIteratorWithStartAndPrefixRequest) (*proto.NewIteratorWithStartAndPrefixResponse, error) { +func (db *DatabaseServer) NewIteratorWithStartAndPrefix(_ context.Context, req *rpcdbproto.NewIteratorWithStartAndPrefixRequest) (*rpcdbproto.NewIteratorWithStartAndPrefixResponse, error) { id := db.nextIteratorID it := db.db.NewIteratorWithStartAndPrefix(req.Start, req.Prefix) db.iterators[id] = it db.nextIteratorID++ - return &proto.NewIteratorWithStartAndPrefixResponse{Id: id}, nil + return &rpcdbproto.NewIteratorWithStartAndPrefixResponse{Id: id}, nil } // IteratorNext ... -func (db *DatabaseServer) IteratorNext(_ context.Context, req *proto.IteratorNextRequest) (*proto.IteratorNextResponse, error) { +func (db *DatabaseServer) IteratorNext(_ context.Context, req *rpcdbproto.IteratorNextRequest) (*rpcdbproto.IteratorNextResponse, error) { it, exists := db.iterators[req.Id] if !exists { return nil, errUnknownIterator } - return &proto.IteratorNextResponse{ + return &rpcdbproto.IteratorNextResponse{ FoundNext: it.Next(), Key: it.Key(), Value: it.Value(), @@ -124,20 +124,20 @@ func (db *DatabaseServer) IteratorNext(_ context.Context, req *proto.IteratorNex } // IteratorError ... -func (db *DatabaseServer) IteratorError(_ context.Context, req *proto.IteratorErrorRequest) (*proto.IteratorErrorResponse, error) { +func (db *DatabaseServer) IteratorError(_ context.Context, req *rpcdbproto.IteratorErrorRequest) (*rpcdbproto.IteratorErrorResponse, error) { it, exists := db.iterators[req.Id] if !exists { return nil, errUnknownIterator } - return &proto.IteratorErrorResponse{}, it.Error() + return &rpcdbproto.IteratorErrorResponse{}, it.Error() } // IteratorRelease ... -func (db *DatabaseServer) IteratorRelease(_ context.Context, req *proto.IteratorReleaseRequest) (*proto.IteratorReleaseResponse, error) { +func (db *DatabaseServer) IteratorRelease(_ context.Context, req *rpcdbproto.IteratorReleaseRequest) (*rpcdbproto.IteratorReleaseResponse, error) { it, exists := db.iterators[req.Id] if exists { delete(db.iterators, req.Id) it.Release() } - return &proto.IteratorReleaseResponse{}, nil + return &rpcdbproto.IteratorReleaseResponse{}, nil } diff --git a/database/rpcdb/db_test.go b/database/rpcdb/db_test.go index ae833d5..f829b4f 100644 --- a/database/rpcdb/db_test.go +++ b/database/rpcdb/db_test.go @@ -15,7 +15,7 @@ import ( "github.com/ava-labs/gecko/database" "github.com/ava-labs/gecko/database/memdb" - "github.com/ava-labs/gecko/database/rpcdb/proto" + "github.com/ava-labs/gecko/database/rpcdb/rpcdbproto" ) const ( @@ -26,7 +26,7 @@ func TestInterface(t *testing.T) { for _, test := range database.Tests { listener := bufconn.Listen(bufSize) server := grpc.NewServer() - proto.RegisterDatabaseServer(server, NewServer(memdb.New())) + rpcdbproto.RegisterDatabaseServer(server, NewServer(memdb.New())) go func() { if err := server.Serve(listener); err != nil { log.Fatalf("Server exited with error: %v", err) @@ -44,7 +44,7 @@ func TestInterface(t *testing.T) { t.Fatalf("Failed to dial: %s", err) } - db := NewClient(proto.NewDatabaseClient(conn)) + db := NewClient(rpcdbproto.NewDatabaseClient(conn)) test(t, db) conn.Close() } diff --git a/database/rpcdb/proto/db.pb.go b/database/rpcdb/rpcdbproto/rpcdb.pb.go similarity index 84% rename from database/rpcdb/proto/db.pb.go rename to database/rpcdb/rpcdbproto/rpcdb.pb.go index 452bad7..e2705f7 100644 --- a/database/rpcdb/proto/db.pb.go +++ b/database/rpcdb/rpcdbproto/rpcdb.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: db.proto +// source: rpcdb.proto -package proto +package rpcdbproto import ( context "context" @@ -35,7 +35,7 @@ func (m *HasRequest) Reset() { *m = HasRequest{} } func (m *HasRequest) String() string { return proto.CompactTextString(m) } func (*HasRequest) ProtoMessage() {} func (*HasRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{0} + return fileDescriptor_af52f4b90339c3f4, []int{0} } func (m *HasRequest) XXX_Unmarshal(b []byte) error { @@ -74,7 +74,7 @@ func (m *HasResponse) Reset() { *m = HasResponse{} } func (m *HasResponse) String() string { return proto.CompactTextString(m) } func (*HasResponse) ProtoMessage() {} func (*HasResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{1} + return fileDescriptor_af52f4b90339c3f4, []int{1} } func (m *HasResponse) XXX_Unmarshal(b []byte) error { @@ -113,7 +113,7 @@ func (m *GetRequest) Reset() { *m = GetRequest{} } func (m *GetRequest) String() string { return proto.CompactTextString(m) } func (*GetRequest) ProtoMessage() {} func (*GetRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{2} + return fileDescriptor_af52f4b90339c3f4, []int{2} } func (m *GetRequest) XXX_Unmarshal(b []byte) error { @@ -152,7 +152,7 @@ func (m *GetResponse) Reset() { *m = GetResponse{} } func (m *GetResponse) String() string { return proto.CompactTextString(m) } func (*GetResponse) ProtoMessage() {} func (*GetResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{3} + return fileDescriptor_af52f4b90339c3f4, []int{3} } func (m *GetResponse) XXX_Unmarshal(b []byte) error { @@ -192,7 +192,7 @@ func (m *PutRequest) Reset() { *m = PutRequest{} } func (m *PutRequest) String() string { return proto.CompactTextString(m) } func (*PutRequest) ProtoMessage() {} func (*PutRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{4} + return fileDescriptor_af52f4b90339c3f4, []int{4} } func (m *PutRequest) XXX_Unmarshal(b []byte) error { @@ -237,7 +237,7 @@ func (m *PutResponse) Reset() { *m = PutResponse{} } func (m *PutResponse) String() string { return proto.CompactTextString(m) } func (*PutResponse) ProtoMessage() {} func (*PutResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{5} + return fileDescriptor_af52f4b90339c3f4, []int{5} } func (m *PutResponse) XXX_Unmarshal(b []byte) error { @@ -269,7 +269,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{6} + return fileDescriptor_af52f4b90339c3f4, []int{6} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -307,7 +307,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{7} + return fileDescriptor_af52f4b90339c3f4, []int{7} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -339,7 +339,7 @@ func (m *StatRequest) Reset() { *m = StatRequest{} } func (m *StatRequest) String() string { return proto.CompactTextString(m) } func (*StatRequest) ProtoMessage() {} func (*StatRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{8} + return fileDescriptor_af52f4b90339c3f4, []int{8} } func (m *StatRequest) XXX_Unmarshal(b []byte) error { @@ -378,7 +378,7 @@ func (m *StatResponse) Reset() { *m = StatResponse{} } func (m *StatResponse) String() string { return proto.CompactTextString(m) } func (*StatResponse) ProtoMessage() {} func (*StatResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{9} + return fileDescriptor_af52f4b90339c3f4, []int{9} } func (m *StatResponse) XXX_Unmarshal(b []byte) error { @@ -418,7 +418,7 @@ func (m *CompactRequest) Reset() { *m = CompactRequest{} } func (m *CompactRequest) String() string { return proto.CompactTextString(m) } func (*CompactRequest) ProtoMessage() {} func (*CompactRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{10} + return fileDescriptor_af52f4b90339c3f4, []int{10} } func (m *CompactRequest) XXX_Unmarshal(b []byte) error { @@ -463,7 +463,7 @@ func (m *CompactResponse) Reset() { *m = CompactResponse{} } func (m *CompactResponse) String() string { return proto.CompactTextString(m) } func (*CompactResponse) ProtoMessage() {} func (*CompactResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{11} + return fileDescriptor_af52f4b90339c3f4, []int{11} } func (m *CompactResponse) XXX_Unmarshal(b []byte) error { @@ -494,7 +494,7 @@ func (m *CloseRequest) Reset() { *m = CloseRequest{} } func (m *CloseRequest) String() string { return proto.CompactTextString(m) } func (*CloseRequest) ProtoMessage() {} func (*CloseRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{12} + return fileDescriptor_af52f4b90339c3f4, []int{12} } func (m *CloseRequest) XXX_Unmarshal(b []byte) error { @@ -525,7 +525,7 @@ func (m *CloseResponse) Reset() { *m = CloseResponse{} } func (m *CloseResponse) String() string { return proto.CompactTextString(m) } func (*CloseResponse) ProtoMessage() {} func (*CloseResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{13} + return fileDescriptor_af52f4b90339c3f4, []int{13} } func (m *CloseResponse) XXX_Unmarshal(b []byte) error { @@ -558,7 +558,7 @@ func (m *WriteBatchRequest) Reset() { *m = WriteBatchRequest{} } func (m *WriteBatchRequest) String() string { return proto.CompactTextString(m) } func (*WriteBatchRequest) ProtoMessage() {} func (*WriteBatchRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{14} + return fileDescriptor_af52f4b90339c3f4, []int{14} } func (m *WriteBatchRequest) XXX_Unmarshal(b []byte) error { @@ -603,7 +603,7 @@ func (m *WriteBatchResponse) Reset() { *m = WriteBatchResponse{} } func (m *WriteBatchResponse) String() string { return proto.CompactTextString(m) } func (*WriteBatchResponse) ProtoMessage() {} func (*WriteBatchResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{15} + return fileDescriptor_af52f4b90339c3f4, []int{15} } func (m *WriteBatchResponse) XXX_Unmarshal(b []byte) error { @@ -634,7 +634,7 @@ func (m *NewIteratorRequest) Reset() { *m = NewIteratorRequest{} } func (m *NewIteratorRequest) String() string { return proto.CompactTextString(m) } func (*NewIteratorRequest) ProtoMessage() {} func (*NewIteratorRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{16} + return fileDescriptor_af52f4b90339c3f4, []int{16} } func (m *NewIteratorRequest) XXX_Unmarshal(b []byte) error { @@ -667,7 +667,7 @@ func (m *NewIteratorWithStartAndPrefixRequest) Reset() { *m = NewIterato func (m *NewIteratorWithStartAndPrefixRequest) String() string { return proto.CompactTextString(m) } func (*NewIteratorWithStartAndPrefixRequest) ProtoMessage() {} func (*NewIteratorWithStartAndPrefixRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{17} + return fileDescriptor_af52f4b90339c3f4, []int{17} } func (m *NewIteratorWithStartAndPrefixRequest) XXX_Unmarshal(b []byte) error { @@ -713,7 +713,7 @@ func (m *NewIteratorWithStartAndPrefixResponse) Reset() { *m = NewIterat func (m *NewIteratorWithStartAndPrefixResponse) String() string { return proto.CompactTextString(m) } func (*NewIteratorWithStartAndPrefixResponse) ProtoMessage() {} func (*NewIteratorWithStartAndPrefixResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{18} + return fileDescriptor_af52f4b90339c3f4, []int{18} } func (m *NewIteratorWithStartAndPrefixResponse) XXX_Unmarshal(b []byte) error { @@ -752,7 +752,7 @@ func (m *IteratorNextRequest) Reset() { *m = IteratorNextRequest{} } func (m *IteratorNextRequest) String() string { return proto.CompactTextString(m) } func (*IteratorNextRequest) ProtoMessage() {} func (*IteratorNextRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{19} + return fileDescriptor_af52f4b90339c3f4, []int{19} } func (m *IteratorNextRequest) XXX_Unmarshal(b []byte) error { @@ -793,7 +793,7 @@ func (m *IteratorNextResponse) Reset() { *m = IteratorNextResponse{} } func (m *IteratorNextResponse) String() string { return proto.CompactTextString(m) } func (*IteratorNextResponse) ProtoMessage() {} func (*IteratorNextResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{20} + return fileDescriptor_af52f4b90339c3f4, []int{20} } func (m *IteratorNextResponse) XXX_Unmarshal(b []byte) error { @@ -846,7 +846,7 @@ func (m *IteratorErrorRequest) Reset() { *m = IteratorErrorRequest{} } func (m *IteratorErrorRequest) String() string { return proto.CompactTextString(m) } func (*IteratorErrorRequest) ProtoMessage() {} func (*IteratorErrorRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{21} + return fileDescriptor_af52f4b90339c3f4, []int{21} } func (m *IteratorErrorRequest) XXX_Unmarshal(b []byte) error { @@ -884,7 +884,7 @@ func (m *IteratorErrorResponse) Reset() { *m = IteratorErrorResponse{} } func (m *IteratorErrorResponse) String() string { return proto.CompactTextString(m) } func (*IteratorErrorResponse) ProtoMessage() {} func (*IteratorErrorResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{22} + return fileDescriptor_af52f4b90339c3f4, []int{22} } func (m *IteratorErrorResponse) XXX_Unmarshal(b []byte) error { @@ -916,7 +916,7 @@ func (m *IteratorReleaseRequest) Reset() { *m = IteratorReleaseRequest{} func (m *IteratorReleaseRequest) String() string { return proto.CompactTextString(m) } func (*IteratorReleaseRequest) ProtoMessage() {} func (*IteratorReleaseRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{23} + return fileDescriptor_af52f4b90339c3f4, []int{23} } func (m *IteratorReleaseRequest) XXX_Unmarshal(b []byte) error { @@ -954,7 +954,7 @@ func (m *IteratorReleaseResponse) Reset() { *m = IteratorReleaseResponse func (m *IteratorReleaseResponse) String() string { return proto.CompactTextString(m) } func (*IteratorReleaseResponse) ProtoMessage() {} func (*IteratorReleaseResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8817812184a13374, []int{24} + return fileDescriptor_af52f4b90339c3f4, []int{24} } func (m *IteratorReleaseResponse) XXX_Unmarshal(b []byte) error { @@ -976,77 +976,78 @@ func (m *IteratorReleaseResponse) XXX_DiscardUnknown() { var xxx_messageInfo_IteratorReleaseResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*HasRequest)(nil), "proto.HasRequest") - proto.RegisterType((*HasResponse)(nil), "proto.HasResponse") - proto.RegisterType((*GetRequest)(nil), "proto.GetRequest") - proto.RegisterType((*GetResponse)(nil), "proto.GetResponse") - proto.RegisterType((*PutRequest)(nil), "proto.PutRequest") - proto.RegisterType((*PutResponse)(nil), "proto.PutResponse") - proto.RegisterType((*DeleteRequest)(nil), "proto.DeleteRequest") - proto.RegisterType((*DeleteResponse)(nil), "proto.DeleteResponse") - proto.RegisterType((*StatRequest)(nil), "proto.StatRequest") - proto.RegisterType((*StatResponse)(nil), "proto.StatResponse") - proto.RegisterType((*CompactRequest)(nil), "proto.CompactRequest") - proto.RegisterType((*CompactResponse)(nil), "proto.CompactResponse") - proto.RegisterType((*CloseRequest)(nil), "proto.CloseRequest") - proto.RegisterType((*CloseResponse)(nil), "proto.CloseResponse") - proto.RegisterType((*WriteBatchRequest)(nil), "proto.WriteBatchRequest") - proto.RegisterType((*WriteBatchResponse)(nil), "proto.WriteBatchResponse") - proto.RegisterType((*NewIteratorRequest)(nil), "proto.NewIteratorRequest") - proto.RegisterType((*NewIteratorWithStartAndPrefixRequest)(nil), "proto.NewIteratorWithStartAndPrefixRequest") - proto.RegisterType((*NewIteratorWithStartAndPrefixResponse)(nil), "proto.NewIteratorWithStartAndPrefixResponse") - proto.RegisterType((*IteratorNextRequest)(nil), "proto.IteratorNextRequest") - proto.RegisterType((*IteratorNextResponse)(nil), "proto.IteratorNextResponse") - proto.RegisterType((*IteratorErrorRequest)(nil), "proto.IteratorErrorRequest") - proto.RegisterType((*IteratorErrorResponse)(nil), "proto.IteratorErrorResponse") - proto.RegisterType((*IteratorReleaseRequest)(nil), "proto.IteratorReleaseRequest") - proto.RegisterType((*IteratorReleaseResponse)(nil), "proto.IteratorReleaseResponse") + proto.RegisterType((*HasRequest)(nil), "rpcdbproto.HasRequest") + proto.RegisterType((*HasResponse)(nil), "rpcdbproto.HasResponse") + proto.RegisterType((*GetRequest)(nil), "rpcdbproto.GetRequest") + proto.RegisterType((*GetResponse)(nil), "rpcdbproto.GetResponse") + proto.RegisterType((*PutRequest)(nil), "rpcdbproto.PutRequest") + proto.RegisterType((*PutResponse)(nil), "rpcdbproto.PutResponse") + proto.RegisterType((*DeleteRequest)(nil), "rpcdbproto.DeleteRequest") + proto.RegisterType((*DeleteResponse)(nil), "rpcdbproto.DeleteResponse") + proto.RegisterType((*StatRequest)(nil), "rpcdbproto.StatRequest") + proto.RegisterType((*StatResponse)(nil), "rpcdbproto.StatResponse") + proto.RegisterType((*CompactRequest)(nil), "rpcdbproto.CompactRequest") + proto.RegisterType((*CompactResponse)(nil), "rpcdbproto.CompactResponse") + proto.RegisterType((*CloseRequest)(nil), "rpcdbproto.CloseRequest") + proto.RegisterType((*CloseResponse)(nil), "rpcdbproto.CloseResponse") + proto.RegisterType((*WriteBatchRequest)(nil), "rpcdbproto.WriteBatchRequest") + proto.RegisterType((*WriteBatchResponse)(nil), "rpcdbproto.WriteBatchResponse") + proto.RegisterType((*NewIteratorRequest)(nil), "rpcdbproto.NewIteratorRequest") + proto.RegisterType((*NewIteratorWithStartAndPrefixRequest)(nil), "rpcdbproto.NewIteratorWithStartAndPrefixRequest") + proto.RegisterType((*NewIteratorWithStartAndPrefixResponse)(nil), "rpcdbproto.NewIteratorWithStartAndPrefixResponse") + proto.RegisterType((*IteratorNextRequest)(nil), "rpcdbproto.IteratorNextRequest") + proto.RegisterType((*IteratorNextResponse)(nil), "rpcdbproto.IteratorNextResponse") + proto.RegisterType((*IteratorErrorRequest)(nil), "rpcdbproto.IteratorErrorRequest") + proto.RegisterType((*IteratorErrorResponse)(nil), "rpcdbproto.IteratorErrorResponse") + proto.RegisterType((*IteratorReleaseRequest)(nil), "rpcdbproto.IteratorReleaseRequest") + proto.RegisterType((*IteratorReleaseResponse)(nil), "rpcdbproto.IteratorReleaseResponse") } -func init() { proto.RegisterFile("db.proto", fileDescriptor_8817812184a13374) } +func init() { proto.RegisterFile("rpcdb.proto", fileDescriptor_af52f4b90339c3f4) } -var fileDescriptor_8817812184a13374 = []byte{ - // 639 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0x5b, 0x4f, 0x13, 0x41, - 0x18, 0x0d, 0xbd, 0x51, 0x4e, 0x2f, 0xc0, 0xb0, 0xdc, 0x46, 0x40, 0x1d, 0xc5, 0x60, 0x6c, 0x30, - 0x41, 0x8d, 0x3e, 0xf8, 0x82, 0x60, 0x40, 0x1f, 0x48, 0xb3, 0x98, 0xf0, 0xe2, 0xcb, 0x40, 0x87, - 0xb0, 0x5a, 0xd8, 0x75, 0x77, 0xaa, 0xe8, 0xaf, 0xf0, 0x27, 0x9b, 0x9d, 0xfd, 0x66, 0x6f, 0x6d, - 0x91, 0xa7, 0xee, 0x7c, 0xdf, 0x39, 0x67, 0x66, 0xbe, 0x39, 0xa7, 0x68, 0x0e, 0xce, 0x77, 0x83, - 0xd0, 0xd7, 0x3e, 0xab, 0x9b, 0x1f, 0xb1, 0x05, 0x1c, 0xcb, 0xc8, 0x55, 0x3f, 0x46, 0x2a, 0xd2, - 0x6c, 0x01, 0xd5, 0xef, 0xea, 0xf7, 0xda, 0xcc, 0xa3, 0x99, 0x9d, 0xb6, 0x1b, 0x7f, 0x8a, 0x87, - 0x68, 0x99, 0x7e, 0x14, 0xf8, 0x37, 0x91, 0x8a, 0x01, 0x57, 0x32, 0x32, 0x80, 0xa6, 0x1b, 0x7f, - 0xc6, 0x02, 0x47, 0x4a, 0x4f, 0x17, 0x78, 0x82, 0x96, 0xe9, 0x93, 0x80, 0x83, 0xfa, 0x4f, 0x39, - 0x1c, 0x29, 0x82, 0x24, 0x0b, 0xf1, 0x1a, 0xe8, 0x8f, 0xa6, 0x8b, 0x64, 0xac, 0x4a, 0x9e, 0xd5, - 0x41, 0xcb, 0xb0, 0x12, 0x69, 0xf1, 0x18, 0x9d, 0x43, 0x35, 0x54, 0x5a, 0x4d, 0x3f, 0xcc, 0x02, - 0xba, 0x16, 0x42, 0xa4, 0xe7, 0x68, 0x9d, 0x6a, 0x99, 0x6e, 0xcd, 0xd1, 0x0c, 0x42, 0x3f, 0x50, - 0xa1, 0x4e, 0x78, 0x73, 0x6e, 0xba, 0x16, 0x02, 0xed, 0x04, 0x4a, 0x57, 0x61, 0xa8, 0x45, 0x5a, - 0x6a, 0xc2, 0x99, 0x6f, 0xf1, 0x1e, 0xdd, 0x03, 0xff, 0x3a, 0x90, 0x17, 0xa9, 0xa2, 0x83, 0x7a, - 0xa4, 0x65, 0xa8, 0xed, 0x85, 0xcd, 0x22, 0xae, 0x0e, 0xbd, 0x6b, 0x4f, 0xdb, 0x0b, 0x99, 0x85, - 0x58, 0xc4, 0x7c, 0xca, 0xa6, 0xf3, 0x75, 0xd1, 0x3e, 0x18, 0xfa, 0x91, 0xbd, 0x93, 0x98, 0x47, - 0x87, 0xd6, 0x04, 0xf8, 0x86, 0xc5, 0xb3, 0xd0, 0xd3, 0xea, 0x83, 0xd4, 0x17, 0x57, 0x76, 0xd3, - 0x6d, 0xd4, 0x82, 0x91, 0x8e, 0xdf, 0xa9, 0xba, 0xd3, 0xda, 0x5b, 0x4c, 0x9e, 0x7c, 0x37, 0x1b, - 0xb1, 0x6b, 0xda, 0x6c, 0x17, 0xb3, 0x03, 0x33, 0x8e, 0x68, 0xad, 0x62, 0x90, 0x0e, 0x21, 0x0b, - 0x73, 0x74, 0x2d, 0x48, 0x38, 0x60, 0xf9, 0xbd, 0xe8, 0x04, 0x0e, 0xd8, 0x89, 0xfa, 0xf5, 0x49, - 0xab, 0x50, 0x6a, 0x3f, 0xb4, 0x07, 0xfd, 0x82, 0xa7, 0xb9, 0xea, 0x99, 0xa7, 0xaf, 0x4e, 0xe3, - 0x9b, 0xef, 0xdf, 0x0c, 0xfa, 0xa1, 0xba, 0xf4, 0x6e, 0xef, 0x9e, 0xcf, 0x0a, 0x1a, 0x81, 0x81, - 0xd1, 0x80, 0x68, 0x25, 0xde, 0x62, 0xfb, 0x3f, 0xaa, 0xf4, 0x38, 0x5d, 0x54, 0xbc, 0x81, 0xd1, - 0xac, 0xb9, 0x15, 0x6f, 0x20, 0xb6, 0xb1, 0x64, 0x59, 0x27, 0xea, 0x36, 0x7d, 0x9d, 0x32, 0xec, - 0x2b, 0x9c, 0x22, 0x8c, 0xe4, 0x36, 0x30, 0x77, 0xe9, 0x8f, 0x6e, 0x06, 0x71, 0x91, 0xdc, 0x9f, - 0x15, 0xac, 0xd1, 0x2a, 0x13, 0x0c, 0x5b, 0xcd, 0x1b, 0xf6, 0x59, 0xa6, 0xfe, 0x31, 0x0c, 0xd3, - 0x59, 0x8d, 0x9d, 0x62, 0x15, 0xcb, 0x25, 0x1c, 0x8d, 0x7a, 0x07, 0x2b, 0xd9, 0x9c, 0x87, 0x4a, - 0xa6, 0xbe, 0x18, 0x93, 0x58, 0xc7, 0xea, 0x18, 0x32, 0x11, 0xd9, 0xfb, 0xdb, 0x40, 0xf3, 0x50, - 0x6a, 0x79, 0x2e, 0x23, 0xc5, 0x7a, 0xa8, 0x1e, 0xcb, 0x88, 0x59, 0x8b, 0x64, 0xff, 0x05, 0x9c, - 0xe5, 0x4b, 0x34, 0x86, 0x1e, 0xaa, 0x47, 0x4a, 0xa7, 0xe8, 0x2c, 0xf8, 0x29, 0x3a, 0x9f, 0xf5, - 0x1e, 0xaa, 0xfd, 0x51, 0x86, 0xce, 0xec, 0x97, 0xa2, 0x73, 0xf1, 0x65, 0x6f, 0xd0, 0x48, 0x6c, - 0xc7, 0x26, 0xba, 0x90, 0x2f, 0x97, 0xaa, 0x44, 0x7b, 0x89, 0x5a, 0x9c, 0x4a, 0x66, 0x25, 0x73, - 0x69, 0xe6, 0x4b, 0x85, 0x1a, 0x11, 0xde, 0x61, 0x96, 0x42, 0xc6, 0xac, 0x64, 0x31, 0xb2, 0x7c, - 0xa5, 0x5c, 0x26, 0xe6, 0x1e, 0xea, 0x26, 0x7b, 0xcc, 0xea, 0xe6, 0x93, 0xc9, 0x9d, 0x62, 0x91, - 0x38, 0xfb, 0x40, 0x16, 0x19, 0xb6, 0x46, 0x98, 0xb1, 0xc4, 0xf2, 0xf5, 0x09, 0x1d, 0x92, 0xf8, - 0x83, 0xcd, 0x3b, 0x3d, 0xcf, 0x5e, 0x10, 0xf7, 0x3e, 0x79, 0xe3, 0xbd, 0xfb, 0x81, 0x69, 0xef, - 0x23, 0xb4, 0xf3, 0x79, 0x60, 0x9c, 0xd8, 0x13, 0xb2, 0xc4, 0x1f, 0x4c, 0xec, 0x91, 0xd0, 0x67, - 0x74, 0x0a, 0x96, 0x66, 0x65, 0x74, 0x3e, 0x10, 0x7c, 0x63, 0x72, 0x93, 0xb4, 0xfa, 0x98, 0x2f, - 0x79, 0x9b, 0x6d, 0x96, 0x08, 0xc5, 0x74, 0xf0, 0xad, 0x69, 0xed, 0x44, 0xf1, 0xbc, 0x61, 0xda, - 0xaf, 0xfe, 0x05, 0x00, 0x00, 0xff, 0xff, 0x84, 0x99, 0x7f, 0xf3, 0x1f, 0x07, 0x00, 0x00, +var fileDescriptor_af52f4b90339c3f4 = []byte{ + // 654 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0x5d, 0x4f, 0xd4, 0x40, + 0x14, 0x0d, 0xbb, 0xcb, 0xd7, 0xd9, 0x0f, 0x60, 0x5c, 0xf9, 0xa8, 0xf2, 0x35, 0x88, 0x41, 0x1f, + 0x88, 0x82, 0xc1, 0x98, 0x90, 0x18, 0x01, 0x03, 0xc6, 0x84, 0x60, 0x21, 0x21, 0x31, 0xbe, 0x0c, + 0xec, 0x10, 0x1a, 0x97, 0x6d, 0x6d, 0x67, 0x15, 0xdf, 0x7d, 0xf1, 0x5f, 0x9b, 0x4e, 0x6f, 0xdb, + 0x99, 0xdd, 0x76, 0xd5, 0xb7, 0xb9, 0x73, 0xcf, 0x39, 0x73, 0xe7, 0xce, 0x3d, 0x83, 0x7a, 0x18, + 0x5c, 0x77, 0xae, 0xb6, 0x83, 0xd0, 0x57, 0x3e, 0x83, 0x0e, 0xf4, 0x9a, 0xaf, 0x00, 0x27, 0x22, + 0x72, 0xe5, 0xb7, 0xbe, 0x8c, 0x14, 0x9b, 0x45, 0xf5, 0xab, 0xfc, 0xb9, 0x38, 0xb6, 0x36, 0xb6, + 0xd5, 0x70, 0xe3, 0x25, 0x5f, 0x45, 0x5d, 0xe7, 0xa3, 0xc0, 0xef, 0x45, 0x32, 0x06, 0xdc, 0x8a, + 0x48, 0x03, 0xa6, 0xdc, 0x78, 0x19, 0x0b, 0x1c, 0x4b, 0x55, 0x2e, 0xb0, 0x81, 0xba, 0xce, 0x93, + 0x40, 0x1b, 0xe3, 0xdf, 0x45, 0xb7, 0x2f, 0x09, 0x92, 0x04, 0xfc, 0x15, 0x70, 0xd6, 0x2f, 0x17, + 0xc9, 0x59, 0x15, 0x93, 0xd5, 0x44, 0x5d, 0xb3, 0x12, 0x69, 0xbe, 0x8e, 0xe6, 0x91, 0xec, 0x4a, + 0x25, 0xcb, 0x8b, 0x99, 0x45, 0x2b, 0x85, 0x10, 0xe9, 0x19, 0xea, 0xe7, 0x4a, 0x64, 0x47, 0x3b, + 0x98, 0x0a, 0x42, 0x3f, 0x90, 0xa1, 0x4a, 0x78, 0xd3, 0x6e, 0x16, 0x73, 0x8e, 0x46, 0x02, 0xa5, + 0xab, 0x30, 0xd4, 0x22, 0x25, 0x14, 0xe1, 0xf4, 0x9a, 0xef, 0xa3, 0x75, 0xe8, 0xdf, 0x05, 0xe2, + 0x3a, 0x53, 0x6c, 0x63, 0x3c, 0x52, 0x22, 0x54, 0xe9, 0x85, 0x75, 0x10, 0xef, 0x76, 0xbd, 0x3b, + 0x4f, 0xa5, 0x17, 0xd2, 0x01, 0x9f, 0xc3, 0x4c, 0xc6, 0xa6, 0xfa, 0x5a, 0x68, 0x1c, 0x76, 0xfd, + 0x28, 0xbd, 0x13, 0x9f, 0x41, 0x93, 0x62, 0x02, 0x28, 0xcc, 0x5d, 0x86, 0x9e, 0x92, 0x07, 0x42, + 0x5d, 0xdf, 0xa6, 0x87, 0x3e, 0x47, 0x2d, 0xe8, 0xab, 0xf8, 0x9d, 0xaa, 0x5b, 0xf5, 0x9d, 0xf9, + 0xed, 0xfc, 0xc1, 0xb7, 0xf3, 0x3e, 0xbb, 0x1a, 0xc3, 0x76, 0x31, 0xd9, 0xd1, 0x3d, 0x89, 0x16, + 0x2b, 0x1a, 0xbe, 0x64, 0xc2, 0xad, 0x8e, 0xba, 0x29, 0x92, 0xb7, 0xc1, 0xcc, 0x53, 0xa9, 0x96, + 0x36, 0xd8, 0xa9, 0xfc, 0xf1, 0x41, 0xc9, 0x50, 0x28, 0x3f, 0x4c, 0x4b, 0xbe, 0xc0, 0x13, 0x63, + 0xf7, 0xd2, 0x53, 0xb7, 0xe7, 0x71, 0x0f, 0xde, 0xf5, 0x3a, 0x67, 0xa1, 0xbc, 0xf1, 0xee, 0x47, + 0x77, 0x6a, 0x1e, 0x13, 0x81, 0x86, 0x51, 0xab, 0x28, 0xe2, 0xaf, 0xb1, 0xf9, 0x17, 0x55, 0x7a, + 0xa6, 0x16, 0x2a, 0x5e, 0x47, 0x6b, 0xd6, 0xdc, 0x8a, 0xd7, 0xe1, 0x9b, 0x78, 0x90, 0xb2, 0x4e, + 0xe5, 0x7d, 0xf6, 0x4e, 0x83, 0xb0, 0x2f, 0x68, 0xdb, 0x30, 0x92, 0x7b, 0x8c, 0xe9, 0x1b, 0xbf, + 0xdf, 0xeb, 0xc4, 0x9b, 0xe4, 0x83, 0x7c, 0x23, 0x1d, 0xb9, 0x4a, 0xc1, 0xe8, 0x56, 0xcd, 0xd1, + 0x7d, 0x9a, 0xab, 0xbf, 0x0f, 0xc3, 0xac, 0x57, 0x43, 0x55, 0x2c, 0xe0, 0xe1, 0x00, 0x8e, 0x5a, + 0xbd, 0x85, 0xf9, 0xbc, 0xcf, 0x5d, 0x29, 0xb2, 0x09, 0x19, 0x92, 0x58, 0xc2, 0xc2, 0x10, 0x32, + 0x11, 0xd9, 0xf9, 0x3d, 0x89, 0xa9, 0x23, 0xa1, 0xc4, 0x95, 0x88, 0x24, 0xdb, 0x43, 0xf5, 0x44, + 0x44, 0xcc, 0x1a, 0x96, 0xfc, 0x6b, 0x70, 0x16, 0x86, 0xf6, 0xa9, 0x21, 0x7b, 0xa8, 0x1e, 0x4b, + 0x65, 0xf3, 0xf2, 0x1f, 0xc1, 0xe6, 0x99, 0x3f, 0xc1, 0x1e, 0xaa, 0x67, 0xfd, 0x01, 0x5e, 0x3e, + 0x9c, 0x36, 0xcf, 0xb0, 0x39, 0x7b, 0x8b, 0x89, 0x64, 0x28, 0x59, 0xf9, 0xa0, 0x3a, 0x4e, 0x51, + 0x8a, 0x04, 0xde, 0xa0, 0x16, 0xfb, 0x98, 0x59, 0x27, 0x18, 0x9f, 0x80, 0xb3, 0x38, 0x9c, 0x20, + 0xea, 0x01, 0x26, 0xc9, 0xa0, 0xcc, 0x3a, 0xc1, 0xf6, 0xbc, 0xf3, 0xa8, 0x30, 0x47, 0x1a, 0xfb, + 0x18, 0xd7, 0x0e, 0x66, 0xd6, 0x31, 0xa6, 0xc9, 0x9d, 0xa5, 0x82, 0x0c, 0xb1, 0x3f, 0x02, 0xb9, + 0xf1, 0xd8, 0xb2, 0x09, 0x1c, 0xfa, 0x06, 0x9c, 0x95, 0xb2, 0x34, 0x89, 0xfd, 0x1a, 0xc3, 0xf2, + 0x48, 0x13, 0xb1, 0x17, 0xa6, 0xc2, 0xbf, 0xb8, 0xd8, 0x79, 0xf9, 0x1f, 0x0c, 0x2a, 0xe3, 0x13, + 0x1a, 0xa6, 0xd5, 0xd8, 0xaa, 0x29, 0x51, 0xe0, 0x55, 0x67, 0xad, 0x1c, 0x40, 0x92, 0x17, 0x68, + 0x5a, 0xbe, 0x61, 0x85, 0x14, 0xd3, 0x7a, 0xce, 0xfa, 0x08, 0x04, 0xa9, 0x7e, 0xc6, 0xcc, 0x80, + 0x95, 0x18, 0x2f, 0x62, 0xd9, 0x8e, 0x74, 0x36, 0x46, 0x62, 0x12, 0xed, 0xab, 0x09, 0x9d, 0xde, + 0xfd, 0x13, 0x00, 0x00, 0xff, 0xff, 0x91, 0xec, 0x29, 0xb2, 0xaa, 0x07, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1085,7 +1086,7 @@ func NewDatabaseClient(cc grpc.ClientConnInterface) DatabaseClient { func (c *databaseClient) Has(ctx context.Context, in *HasRequest, opts ...grpc.CallOption) (*HasResponse, error) { out := new(HasResponse) - err := c.cc.Invoke(ctx, "/proto.Database/Has", in, out, opts...) + err := c.cc.Invoke(ctx, "/rpcdbproto.Database/Has", in, out, opts...) if err != nil { return nil, err } @@ -1094,7 +1095,7 @@ func (c *databaseClient) Has(ctx context.Context, in *HasRequest, opts ...grpc.C func (c *databaseClient) Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) { out := new(GetResponse) - err := c.cc.Invoke(ctx, "/proto.Database/Get", in, out, opts...) + err := c.cc.Invoke(ctx, "/rpcdbproto.Database/Get", in, out, opts...) if err != nil { return nil, err } @@ -1103,7 +1104,7 @@ func (c *databaseClient) Get(ctx context.Context, in *GetRequest, opts ...grpc.C func (c *databaseClient) Put(ctx context.Context, in *PutRequest, opts ...grpc.CallOption) (*PutResponse, error) { out := new(PutResponse) - err := c.cc.Invoke(ctx, "/proto.Database/Put", in, out, opts...) + err := c.cc.Invoke(ctx, "/rpcdbproto.Database/Put", in, out, opts...) if err != nil { return nil, err } @@ -1112,7 +1113,7 @@ func (c *databaseClient) Put(ctx context.Context, in *PutRequest, opts ...grpc.C func (c *databaseClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { out := new(DeleteResponse) - err := c.cc.Invoke(ctx, "/proto.Database/Delete", in, out, opts...) + err := c.cc.Invoke(ctx, "/rpcdbproto.Database/Delete", in, out, opts...) if err != nil { return nil, err } @@ -1121,7 +1122,7 @@ func (c *databaseClient) Delete(ctx context.Context, in *DeleteRequest, opts ... func (c *databaseClient) Stat(ctx context.Context, in *StatRequest, opts ...grpc.CallOption) (*StatResponse, error) { out := new(StatResponse) - err := c.cc.Invoke(ctx, "/proto.Database/Stat", in, out, opts...) + err := c.cc.Invoke(ctx, "/rpcdbproto.Database/Stat", in, out, opts...) if err != nil { return nil, err } @@ -1130,7 +1131,7 @@ func (c *databaseClient) Stat(ctx context.Context, in *StatRequest, opts ...grpc func (c *databaseClient) Compact(ctx context.Context, in *CompactRequest, opts ...grpc.CallOption) (*CompactResponse, error) { out := new(CompactResponse) - err := c.cc.Invoke(ctx, "/proto.Database/Compact", in, out, opts...) + err := c.cc.Invoke(ctx, "/rpcdbproto.Database/Compact", in, out, opts...) if err != nil { return nil, err } @@ -1139,7 +1140,7 @@ func (c *databaseClient) Compact(ctx context.Context, in *CompactRequest, opts . func (c *databaseClient) Close(ctx context.Context, in *CloseRequest, opts ...grpc.CallOption) (*CloseResponse, error) { out := new(CloseResponse) - err := c.cc.Invoke(ctx, "/proto.Database/Close", in, out, opts...) + err := c.cc.Invoke(ctx, "/rpcdbproto.Database/Close", in, out, opts...) if err != nil { return nil, err } @@ -1148,7 +1149,7 @@ func (c *databaseClient) Close(ctx context.Context, in *CloseRequest, opts ...gr func (c *databaseClient) WriteBatch(ctx context.Context, in *WriteBatchRequest, opts ...grpc.CallOption) (*WriteBatchResponse, error) { out := new(WriteBatchResponse) - err := c.cc.Invoke(ctx, "/proto.Database/WriteBatch", in, out, opts...) + err := c.cc.Invoke(ctx, "/rpcdbproto.Database/WriteBatch", in, out, opts...) if err != nil { return nil, err } @@ -1157,7 +1158,7 @@ func (c *databaseClient) WriteBatch(ctx context.Context, in *WriteBatchRequest, func (c *databaseClient) NewIteratorWithStartAndPrefix(ctx context.Context, in *NewIteratorWithStartAndPrefixRequest, opts ...grpc.CallOption) (*NewIteratorWithStartAndPrefixResponse, error) { out := new(NewIteratorWithStartAndPrefixResponse) - err := c.cc.Invoke(ctx, "/proto.Database/NewIteratorWithStartAndPrefix", in, out, opts...) + err := c.cc.Invoke(ctx, "/rpcdbproto.Database/NewIteratorWithStartAndPrefix", in, out, opts...) if err != nil { return nil, err } @@ -1166,7 +1167,7 @@ func (c *databaseClient) NewIteratorWithStartAndPrefix(ctx context.Context, in * func (c *databaseClient) IteratorNext(ctx context.Context, in *IteratorNextRequest, opts ...grpc.CallOption) (*IteratorNextResponse, error) { out := new(IteratorNextResponse) - err := c.cc.Invoke(ctx, "/proto.Database/IteratorNext", in, out, opts...) + err := c.cc.Invoke(ctx, "/rpcdbproto.Database/IteratorNext", in, out, opts...) if err != nil { return nil, err } @@ -1175,7 +1176,7 @@ func (c *databaseClient) IteratorNext(ctx context.Context, in *IteratorNextReque func (c *databaseClient) IteratorError(ctx context.Context, in *IteratorErrorRequest, opts ...grpc.CallOption) (*IteratorErrorResponse, error) { out := new(IteratorErrorResponse) - err := c.cc.Invoke(ctx, "/proto.Database/IteratorError", in, out, opts...) + err := c.cc.Invoke(ctx, "/rpcdbproto.Database/IteratorError", in, out, opts...) if err != nil { return nil, err } @@ -1184,7 +1185,7 @@ func (c *databaseClient) IteratorError(ctx context.Context, in *IteratorErrorReq func (c *databaseClient) IteratorRelease(ctx context.Context, in *IteratorReleaseRequest, opts ...grpc.CallOption) (*IteratorReleaseResponse, error) { out := new(IteratorReleaseResponse) - err := c.cc.Invoke(ctx, "/proto.Database/IteratorRelease", in, out, opts...) + err := c.cc.Invoke(ctx, "/rpcdbproto.Database/IteratorRelease", in, out, opts...) if err != nil { return nil, err } @@ -1262,7 +1263,7 @@ func _Database_Has_Handler(srv interface{}, ctx context.Context, dec func(interf } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Database/Has", + FullMethod: "/rpcdbproto.Database/Has", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(DatabaseServer).Has(ctx, req.(*HasRequest)) @@ -1280,7 +1281,7 @@ func _Database_Get_Handler(srv interface{}, ctx context.Context, dec func(interf } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Database/Get", + FullMethod: "/rpcdbproto.Database/Get", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(DatabaseServer).Get(ctx, req.(*GetRequest)) @@ -1298,7 +1299,7 @@ func _Database_Put_Handler(srv interface{}, ctx context.Context, dec func(interf } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Database/Put", + FullMethod: "/rpcdbproto.Database/Put", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(DatabaseServer).Put(ctx, req.(*PutRequest)) @@ -1316,7 +1317,7 @@ func _Database_Delete_Handler(srv interface{}, ctx context.Context, dec func(int } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Database/Delete", + FullMethod: "/rpcdbproto.Database/Delete", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(DatabaseServer).Delete(ctx, req.(*DeleteRequest)) @@ -1334,7 +1335,7 @@ func _Database_Stat_Handler(srv interface{}, ctx context.Context, dec func(inter } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Database/Stat", + FullMethod: "/rpcdbproto.Database/Stat", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(DatabaseServer).Stat(ctx, req.(*StatRequest)) @@ -1352,7 +1353,7 @@ func _Database_Compact_Handler(srv interface{}, ctx context.Context, dec func(in } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Database/Compact", + FullMethod: "/rpcdbproto.Database/Compact", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(DatabaseServer).Compact(ctx, req.(*CompactRequest)) @@ -1370,7 +1371,7 @@ func _Database_Close_Handler(srv interface{}, ctx context.Context, dec func(inte } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Database/Close", + FullMethod: "/rpcdbproto.Database/Close", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(DatabaseServer).Close(ctx, req.(*CloseRequest)) @@ -1388,7 +1389,7 @@ func _Database_WriteBatch_Handler(srv interface{}, ctx context.Context, dec func } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Database/WriteBatch", + FullMethod: "/rpcdbproto.Database/WriteBatch", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(DatabaseServer).WriteBatch(ctx, req.(*WriteBatchRequest)) @@ -1406,7 +1407,7 @@ func _Database_NewIteratorWithStartAndPrefix_Handler(srv interface{}, ctx contex } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Database/NewIteratorWithStartAndPrefix", + FullMethod: "/rpcdbproto.Database/NewIteratorWithStartAndPrefix", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(DatabaseServer).NewIteratorWithStartAndPrefix(ctx, req.(*NewIteratorWithStartAndPrefixRequest)) @@ -1424,7 +1425,7 @@ func _Database_IteratorNext_Handler(srv interface{}, ctx context.Context, dec fu } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Database/IteratorNext", + FullMethod: "/rpcdbproto.Database/IteratorNext", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(DatabaseServer).IteratorNext(ctx, req.(*IteratorNextRequest)) @@ -1442,7 +1443,7 @@ func _Database_IteratorError_Handler(srv interface{}, ctx context.Context, dec f } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Database/IteratorError", + FullMethod: "/rpcdbproto.Database/IteratorError", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(DatabaseServer).IteratorError(ctx, req.(*IteratorErrorRequest)) @@ -1460,7 +1461,7 @@ func _Database_IteratorRelease_Handler(srv interface{}, ctx context.Context, dec } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Database/IteratorRelease", + FullMethod: "/rpcdbproto.Database/IteratorRelease", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(DatabaseServer).IteratorRelease(ctx, req.(*IteratorReleaseRequest)) @@ -1469,7 +1470,7 @@ func _Database_IteratorRelease_Handler(srv interface{}, ctx context.Context, dec } var _Database_serviceDesc = grpc.ServiceDesc{ - ServiceName: "proto.Database", + ServiceName: "rpcdbproto.Database", HandlerType: (*DatabaseServer)(nil), Methods: []grpc.MethodDesc{ { @@ -1522,5 +1523,5 @@ var _Database_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "db.proto", + Metadata: "rpcdb.proto", } diff --git a/database/rpcdb/proto/db.proto b/database/rpcdb/rpcdbproto/rpcdb.proto similarity index 98% rename from database/rpcdb/proto/db.proto rename to database/rpcdb/rpcdbproto/rpcdb.proto index 1f6f60c..cabd5d8 100644 --- a/database/rpcdb/proto/db.proto +++ b/database/rpcdb/rpcdbproto/rpcdb.proto @@ -1,5 +1,5 @@ syntax = "proto3"; -package proto; +package rpcdbproto; message HasRequest { bytes key = 1; diff --git a/vms/rpcchainvm/ghttp/gconn/conn_client.go b/vms/rpcchainvm/ghttp/gconn/conn_client.go index d35e1a4..7807982 100644 --- a/vms/rpcchainvm/ghttp/gconn/conn_client.go +++ b/vms/rpcchainvm/ghttp/gconn/conn_client.go @@ -11,19 +11,19 @@ import ( "time" "github.com/ava-labs/gecko/utils/wrappers" - "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gconn/proto" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gconn/gconnproto" ) // Client is an implementation of a messenger channel that talks over RPC. type Client struct { - client proto.ConnClient + client gconnproto.ConnClient local net.Addr remote net.Addr toClose []io.Closer } // NewClient returns a database instance connected to a remote database instance -func NewClient(client proto.ConnClient, local, remote net.Addr, toClose ...io.Closer) *Client { +func NewClient(client gconnproto.ConnClient, local, remote net.Addr, toClose ...io.Closer) *Client { return &Client{ client: client, local: local, @@ -34,7 +34,7 @@ func NewClient(client proto.ConnClient, local, remote net.Addr, toClose ...io.Cl // Read ... func (c *Client) Read(p []byte) (int, error) { - resp, err := c.client.Read(context.Background(), &proto.ReadRequest{ + resp, err := c.client.Read(context.Background(), &gconnproto.ReadRequest{ Length: int32(len(p)), }) if err != nil { @@ -51,7 +51,7 @@ func (c *Client) Read(p []byte) (int, error) { // Write ... func (c *Client) Write(b []byte) (int, error) { - resp, err := c.client.Write(context.Background(), &proto.WriteRequest{ + resp, err := c.client.Write(context.Background(), &gconnproto.WriteRequest{ Payload: b, }) if err != nil { @@ -66,7 +66,7 @@ func (c *Client) Write(b []byte) (int, error) { // Close ... func (c *Client) Close() error { - _, err := c.client.Close(context.Background(), &proto.CloseRequest{}) + _, err := c.client.Close(context.Background(), &gconnproto.CloseRequest{}) errs := wrappers.Errs{} errs.Add(err) for _, toClose := range c.toClose { @@ -87,7 +87,7 @@ func (c *Client) SetDeadline(t time.Time) error { if err != nil { return err } - _, err = c.client.SetDeadline(context.Background(), &proto.SetDeadlineRequest{ + _, err = c.client.SetDeadline(context.Background(), &gconnproto.SetDeadlineRequest{ Time: bytes, }) return err @@ -99,7 +99,7 @@ func (c *Client) SetReadDeadline(t time.Time) error { if err != nil { return err } - _, err = c.client.SetReadDeadline(context.Background(), &proto.SetReadDeadlineRequest{ + _, err = c.client.SetReadDeadline(context.Background(), &gconnproto.SetReadDeadlineRequest{ Time: bytes, }) return err @@ -111,7 +111,7 @@ func (c *Client) SetWriteDeadline(t time.Time) error { if err != nil { return err } - _, err = c.client.SetWriteDeadline(context.Background(), &proto.SetWriteDeadlineRequest{ + _, err = c.client.SetWriteDeadline(context.Background(), &gconnproto.SetWriteDeadlineRequest{ Time: bytes, }) return err diff --git a/vms/rpcchainvm/ghttp/gconn/conn_server.go b/vms/rpcchainvm/ghttp/gconn/conn_server.go index 287463d..247a15a 100644 --- a/vms/rpcchainvm/ghttp/gconn/conn_server.go +++ b/vms/rpcchainvm/ghttp/gconn/conn_server.go @@ -8,7 +8,7 @@ import ( "net" "time" - "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gconn/proto" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gconn/gconnproto" ) // Server is a http.Handler that is managed over RPC. @@ -20,10 +20,10 @@ func NewServer(conn net.Conn) *Server { } // Read ... -func (s *Server) Read(ctx context.Context, req *proto.ReadRequest) (*proto.ReadResponse, error) { +func (s *Server) Read(ctx context.Context, req *gconnproto.ReadRequest) (*gconnproto.ReadResponse, error) { buf := make([]byte, int(req.Length)) n, err := s.conn.Read(buf) - resp := &proto.ReadResponse{ + resp := &gconnproto.ReadResponse{ Read: buf[:n], } if err != nil { @@ -34,47 +34,47 @@ func (s *Server) Read(ctx context.Context, req *proto.ReadRequest) (*proto.ReadR } // Write ... -func (s *Server) Write(ctx context.Context, req *proto.WriteRequest) (*proto.WriteResponse, error) { +func (s *Server) Write(ctx context.Context, req *gconnproto.WriteRequest) (*gconnproto.WriteResponse, error) { n, err := s.conn.Write(req.Payload) if err != nil { return nil, err } - return &proto.WriteResponse{ + return &gconnproto.WriteResponse{ Length: int32(n), }, nil } // Close ... -func (s *Server) Close(ctx context.Context, req *proto.CloseRequest) (*proto.CloseResponse, error) { - return &proto.CloseResponse{}, s.conn.Close() +func (s *Server) Close(ctx context.Context, req *gconnproto.CloseRequest) (*gconnproto.CloseResponse, error) { + return &gconnproto.CloseResponse{}, s.conn.Close() } // SetDeadline ... -func (s *Server) SetDeadline(ctx context.Context, req *proto.SetDeadlineRequest) (*proto.SetDeadlineResponse, error) { +func (s *Server) SetDeadline(ctx context.Context, req *gconnproto.SetDeadlineRequest) (*gconnproto.SetDeadlineResponse, error) { deadline := time.Time{} err := deadline.UnmarshalBinary(req.Time) if err != nil { return nil, err } - return &proto.SetDeadlineResponse{}, s.conn.SetDeadline(deadline) + return &gconnproto.SetDeadlineResponse{}, s.conn.SetDeadline(deadline) } // SetReadDeadline ... -func (s *Server) SetReadDeadline(ctx context.Context, req *proto.SetReadDeadlineRequest) (*proto.SetReadDeadlineResponse, error) { +func (s *Server) SetReadDeadline(ctx context.Context, req *gconnproto.SetReadDeadlineRequest) (*gconnproto.SetReadDeadlineResponse, error) { deadline := time.Time{} err := deadline.UnmarshalBinary(req.Time) if err != nil { return nil, err } - return &proto.SetReadDeadlineResponse{}, s.conn.SetReadDeadline(deadline) + return &gconnproto.SetReadDeadlineResponse{}, s.conn.SetReadDeadline(deadline) } // SetWriteDeadline ... -func (s *Server) SetWriteDeadline(ctx context.Context, req *proto.SetWriteDeadlineRequest) (*proto.SetWriteDeadlineResponse, error) { +func (s *Server) SetWriteDeadline(ctx context.Context, req *gconnproto.SetWriteDeadlineRequest) (*gconnproto.SetWriteDeadlineResponse, error) { deadline := time.Time{} err := deadline.UnmarshalBinary(req.Time) if err != nil { return nil, err } - return &proto.SetWriteDeadlineResponse{}, s.conn.SetWriteDeadline(deadline) + return &gconnproto.SetWriteDeadlineResponse{}, s.conn.SetWriteDeadline(deadline) } diff --git a/vms/rpcchainvm/ghttp/gconn/proto/conn.pb.go b/vms/rpcchainvm/ghttp/gconn/gconnproto/gconn.pb.go similarity index 84% rename from vms/rpcchainvm/ghttp/gconn/proto/conn.pb.go rename to vms/rpcchainvm/ghttp/gconn/gconnproto/gconn.pb.go index 6a4e46f..1bea03f 100644 --- a/vms/rpcchainvm/ghttp/gconn/proto/conn.pb.go +++ b/vms/rpcchainvm/ghttp/gconn/gconnproto/gconn.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: conn.proto +// source: gconn.proto -package proto +package gconnproto import ( context "context" @@ -35,7 +35,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f401a58c1fc7ceef, []int{0} + return fileDescriptor_aa209fc9da7fc9d0, []int{0} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -76,7 +76,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f401a58c1fc7ceef, []int{1} + return fileDescriptor_aa209fc9da7fc9d0, []int{1} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -129,7 +129,7 @@ func (m *WriteRequest) Reset() { *m = WriteRequest{} } func (m *WriteRequest) String() string { return proto.CompactTextString(m) } func (*WriteRequest) ProtoMessage() {} func (*WriteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f401a58c1fc7ceef, []int{2} + return fileDescriptor_aa209fc9da7fc9d0, []int{2} } func (m *WriteRequest) XXX_Unmarshal(b []byte) error { @@ -170,7 +170,7 @@ func (m *WriteResponse) Reset() { *m = WriteResponse{} } func (m *WriteResponse) String() string { return proto.CompactTextString(m) } func (*WriteResponse) ProtoMessage() {} func (*WriteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f401a58c1fc7ceef, []int{3} + return fileDescriptor_aa209fc9da7fc9d0, []int{3} } func (m *WriteResponse) XXX_Unmarshal(b []byte) error { @@ -222,7 +222,7 @@ func (m *CloseRequest) Reset() { *m = CloseRequest{} } func (m *CloseRequest) String() string { return proto.CompactTextString(m) } func (*CloseRequest) ProtoMessage() {} func (*CloseRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f401a58c1fc7ceef, []int{4} + return fileDescriptor_aa209fc9da7fc9d0, []int{4} } func (m *CloseRequest) XXX_Unmarshal(b []byte) error { @@ -253,7 +253,7 @@ func (m *CloseResponse) Reset() { *m = CloseResponse{} } func (m *CloseResponse) String() string { return proto.CompactTextString(m) } func (*CloseResponse) ProtoMessage() {} func (*CloseResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f401a58c1fc7ceef, []int{5} + return fileDescriptor_aa209fc9da7fc9d0, []int{5} } func (m *CloseResponse) XXX_Unmarshal(b []byte) error { @@ -285,7 +285,7 @@ func (m *SetDeadlineRequest) Reset() { *m = SetDeadlineRequest{} } func (m *SetDeadlineRequest) String() string { return proto.CompactTextString(m) } func (*SetDeadlineRequest) ProtoMessage() {} func (*SetDeadlineRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f401a58c1fc7ceef, []int{6} + return fileDescriptor_aa209fc9da7fc9d0, []int{6} } func (m *SetDeadlineRequest) XXX_Unmarshal(b []byte) error { @@ -323,7 +323,7 @@ func (m *SetDeadlineResponse) Reset() { *m = SetDeadlineResponse{} } func (m *SetDeadlineResponse) String() string { return proto.CompactTextString(m) } func (*SetDeadlineResponse) ProtoMessage() {} func (*SetDeadlineResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f401a58c1fc7ceef, []int{7} + return fileDescriptor_aa209fc9da7fc9d0, []int{7} } func (m *SetDeadlineResponse) XXX_Unmarshal(b []byte) error { @@ -355,7 +355,7 @@ func (m *SetReadDeadlineRequest) Reset() { *m = SetReadDeadlineRequest{} func (m *SetReadDeadlineRequest) String() string { return proto.CompactTextString(m) } func (*SetReadDeadlineRequest) ProtoMessage() {} func (*SetReadDeadlineRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f401a58c1fc7ceef, []int{8} + return fileDescriptor_aa209fc9da7fc9d0, []int{8} } func (m *SetReadDeadlineRequest) XXX_Unmarshal(b []byte) error { @@ -393,7 +393,7 @@ func (m *SetReadDeadlineResponse) Reset() { *m = SetReadDeadlineResponse func (m *SetReadDeadlineResponse) String() string { return proto.CompactTextString(m) } func (*SetReadDeadlineResponse) ProtoMessage() {} func (*SetReadDeadlineResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f401a58c1fc7ceef, []int{9} + return fileDescriptor_aa209fc9da7fc9d0, []int{9} } func (m *SetReadDeadlineResponse) XXX_Unmarshal(b []byte) error { @@ -425,7 +425,7 @@ func (m *SetWriteDeadlineRequest) Reset() { *m = SetWriteDeadlineRequest func (m *SetWriteDeadlineRequest) String() string { return proto.CompactTextString(m) } func (*SetWriteDeadlineRequest) ProtoMessage() {} func (*SetWriteDeadlineRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f401a58c1fc7ceef, []int{10} + return fileDescriptor_aa209fc9da7fc9d0, []int{10} } func (m *SetWriteDeadlineRequest) XXX_Unmarshal(b []byte) error { @@ -463,7 +463,7 @@ func (m *SetWriteDeadlineResponse) Reset() { *m = SetWriteDeadlineRespon func (m *SetWriteDeadlineResponse) String() string { return proto.CompactTextString(m) } func (*SetWriteDeadlineResponse) ProtoMessage() {} func (*SetWriteDeadlineResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f401a58c1fc7ceef, []int{11} + return fileDescriptor_aa209fc9da7fc9d0, []int{11} } func (m *SetWriteDeadlineResponse) XXX_Unmarshal(b []byte) error { @@ -485,46 +485,47 @@ func (m *SetWriteDeadlineResponse) XXX_DiscardUnknown() { var xxx_messageInfo_SetWriteDeadlineResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*ReadRequest)(nil), "proto.ReadRequest") - proto.RegisterType((*ReadResponse)(nil), "proto.ReadResponse") - proto.RegisterType((*WriteRequest)(nil), "proto.WriteRequest") - proto.RegisterType((*WriteResponse)(nil), "proto.WriteResponse") - proto.RegisterType((*CloseRequest)(nil), "proto.CloseRequest") - proto.RegisterType((*CloseResponse)(nil), "proto.CloseResponse") - proto.RegisterType((*SetDeadlineRequest)(nil), "proto.SetDeadlineRequest") - proto.RegisterType((*SetDeadlineResponse)(nil), "proto.SetDeadlineResponse") - proto.RegisterType((*SetReadDeadlineRequest)(nil), "proto.SetReadDeadlineRequest") - proto.RegisterType((*SetReadDeadlineResponse)(nil), "proto.SetReadDeadlineResponse") - proto.RegisterType((*SetWriteDeadlineRequest)(nil), "proto.SetWriteDeadlineRequest") - proto.RegisterType((*SetWriteDeadlineResponse)(nil), "proto.SetWriteDeadlineResponse") + proto.RegisterType((*ReadRequest)(nil), "gconnproto.ReadRequest") + proto.RegisterType((*ReadResponse)(nil), "gconnproto.ReadResponse") + proto.RegisterType((*WriteRequest)(nil), "gconnproto.WriteRequest") + proto.RegisterType((*WriteResponse)(nil), "gconnproto.WriteResponse") + proto.RegisterType((*CloseRequest)(nil), "gconnproto.CloseRequest") + proto.RegisterType((*CloseResponse)(nil), "gconnproto.CloseResponse") + proto.RegisterType((*SetDeadlineRequest)(nil), "gconnproto.SetDeadlineRequest") + proto.RegisterType((*SetDeadlineResponse)(nil), "gconnproto.SetDeadlineResponse") + proto.RegisterType((*SetReadDeadlineRequest)(nil), "gconnproto.SetReadDeadlineRequest") + proto.RegisterType((*SetReadDeadlineResponse)(nil), "gconnproto.SetReadDeadlineResponse") + proto.RegisterType((*SetWriteDeadlineRequest)(nil), "gconnproto.SetWriteDeadlineRequest") + proto.RegisterType((*SetWriteDeadlineResponse)(nil), "gconnproto.SetWriteDeadlineResponse") } -func init() { proto.RegisterFile("conn.proto", fileDescriptor_f401a58c1fc7ceef) } +func init() { proto.RegisterFile("gconn.proto", fileDescriptor_aa209fc9da7fc9d0) } -var fileDescriptor_f401a58c1fc7ceef = []byte{ - // 351 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0xd1, 0x4e, 0xea, 0x40, - 0x10, 0x4d, 0x2f, 0x2d, 0x5c, 0x87, 0x22, 0x66, 0x40, 0x2c, 0x9b, 0xa8, 0x64, 0x13, 0x93, 0x3e, - 0x28, 0x26, 0xf8, 0x09, 0xf0, 0x01, 0x66, 0x79, 0xe0, 0xb9, 0xda, 0x89, 0x92, 0xd4, 0x5d, 0x6c, - 0xd7, 0x07, 0xff, 0xc1, 0x8f, 0x36, 0x6c, 0xb7, 0xa5, 0x05, 0x9a, 0xe0, 0x53, 0xf7, 0xec, 0x39, - 0x73, 0x66, 0x7a, 0x66, 0x01, 0x5e, 0x95, 0x94, 0xd3, 0x4d, 0xaa, 0xb4, 0x42, 0xcf, 0x7c, 0xf8, - 0x1d, 0x74, 0x05, 0x45, 0xb1, 0xa0, 0xcf, 0x2f, 0xca, 0x34, 0x8e, 0xa0, 0x9d, 0x90, 0x7c, 0xd3, - 0xef, 0x81, 0x33, 0x71, 0x42, 0x4f, 0x58, 0xc4, 0x05, 0xf8, 0xb9, 0x2c, 0xdb, 0x28, 0x99, 0x11, - 0x22, 0xb8, 0x29, 0x45, 0xb1, 0x51, 0xf9, 0xc2, 0x9c, 0x71, 0x08, 0x1e, 0xa5, 0xa9, 0x4a, 0x83, - 0x7f, 0x13, 0x27, 0x3c, 0x13, 0x39, 0xc0, 0x00, 0x3a, 0xe6, 0x40, 0x71, 0xd0, 0x9a, 0x38, 0xe1, - 0x7f, 0x51, 0x40, 0x1e, 0x82, 0xbf, 0x4a, 0xd7, 0x9a, 0x8a, 0xde, 0x01, 0x74, 0x36, 0xd1, 0x77, - 0xa2, 0x4a, 0xdb, 0x02, 0xf2, 0x15, 0xf4, 0xac, 0xd2, 0xb6, 0x6f, 0x18, 0xf3, 0xcf, 0x23, 0x9c, - 0x83, 0x3f, 0x4f, 0x54, 0x56, 0x8c, 0xc0, 0xfb, 0xd0, 0xb3, 0x38, 0x6f, 0xc4, 0x43, 0xc0, 0x25, - 0xe9, 0x05, 0x45, 0x71, 0xb2, 0x96, 0xe5, 0xa4, 0x08, 0xae, 0x5e, 0x7f, 0x50, 0xf1, 0xf7, 0xdb, - 0x33, 0xbf, 0x84, 0x41, 0x4d, 0x69, 0x0d, 0xee, 0x61, 0xb4, 0x24, 0xbd, 0xcd, 0xee, 0x14, 0x93, - 0x31, 0x5c, 0x1d, 0xa8, 0xad, 0xd1, 0x83, 0xa1, 0x4c, 0x0c, 0xa7, 0x38, 0x31, 0x08, 0x0e, 0xe5, - 0xb9, 0xd5, 0xec, 0xa7, 0x05, 0xee, 0x5c, 0x49, 0x89, 0x8f, 0xe0, 0x6e, 0x7b, 0x21, 0xe6, 0x6f, - 0x62, 0x5a, 0x79, 0x09, 0x6c, 0x50, 0xbb, 0xb3, 0xb9, 0xcf, 0xc0, 0x33, 0x96, 0x58, 0xb0, 0xd5, - 0x05, 0xb2, 0x61, 0xfd, 0x72, 0x57, 0x63, 0x32, 0x2d, 0x6b, 0xaa, 0x89, 0x97, 0x35, 0xb5, 0xd8, - 0x71, 0x01, 0xdd, 0x4a, 0x98, 0x38, 0xb6, 0xa2, 0xc3, 0x55, 0x30, 0x76, 0x8c, 0xb2, 0x2e, 0xcf, - 0xd0, 0xdf, 0x4b, 0x13, 0xaf, 0x77, 0xf2, 0x23, 0x3b, 0x61, 0x37, 0x4d, 0xb4, 0x75, 0x5c, 0xc2, - 0xc5, 0x7e, 0xaa, 0x58, 0xa9, 0x39, 0xb6, 0x1d, 0x76, 0xdb, 0xc8, 0xe7, 0xa6, 0x2f, 0x6d, 0xc3, - 0x3f, 0xfd, 0x06, 0x00, 0x00, 0xff, 0xff, 0xe3, 0x73, 0x4d, 0x43, 0x9e, 0x03, 0x00, 0x00, +var fileDescriptor_aa209fc9da7fc9d0 = []byte{ + // 361 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0x4d, 0x4f, 0x22, 0x41, + 0x10, 0xcd, 0x2c, 0x03, 0xec, 0x16, 0xc3, 0xb2, 0xa9, 0x55, 0x68, 0xe6, 0xa0, 0xa4, 0xd5, 0x64, + 0x0e, 0xca, 0x41, 0x4f, 0x26, 0xde, 0xf0, 0xec, 0xa1, 0x39, 0x90, 0x98, 0x78, 0x18, 0x9d, 0x0a, + 0x92, 0x8c, 0xdd, 0x38, 0xd3, 0x1e, 0xfc, 0x87, 0xfe, 0x2c, 0x43, 0x4f, 0x0f, 0xcc, 0x07, 0x10, + 0xbc, 0xd5, 0x4b, 0xbd, 0x7a, 0x55, 0xfd, 0x5e, 0x43, 0x67, 0xfe, 0xa2, 0xa4, 0x1c, 0x2f, 0x13, + 0xa5, 0x15, 0x82, 0x01, 0xa6, 0xe6, 0x17, 0xd0, 0x11, 0x14, 0x46, 0x82, 0xde, 0x3f, 0x28, 0xd5, + 0xd8, 0x87, 0x56, 0x4c, 0x72, 0xae, 0x5f, 0x99, 0x33, 0x72, 0x82, 0xa6, 0xb0, 0x88, 0x0b, 0xf0, + 0x32, 0x5a, 0xba, 0x54, 0x32, 0x25, 0x44, 0x70, 0x13, 0x0a, 0x23, 0xc3, 0xf2, 0x84, 0xa9, 0xf1, + 0x08, 0x9a, 0x94, 0x24, 0x2a, 0x61, 0xbf, 0x46, 0x4e, 0xf0, 0x47, 0x64, 0x00, 0x19, 0xb4, 0x4d, + 0x41, 0x11, 0x6b, 0x8c, 0x9c, 0xe0, 0xb7, 0xc8, 0x21, 0x0f, 0xc0, 0x9b, 0x25, 0x0b, 0x4d, 0xf9, + 0x6e, 0x06, 0xed, 0x65, 0xf8, 0x19, 0xab, 0xb5, 0x6c, 0x0e, 0xf9, 0x0c, 0xba, 0x96, 0x69, 0xd7, + 0xef, 0x38, 0xf3, 0xc7, 0x27, 0xfc, 0x05, 0x6f, 0x12, 0xab, 0x34, 0x3f, 0x81, 0xf7, 0xa0, 0x6b, + 0x71, 0xb6, 0x88, 0x07, 0x80, 0x53, 0xd2, 0xf7, 0x14, 0x46, 0xf1, 0x42, 0xae, 0x2f, 0x45, 0x70, + 0xf5, 0xe2, 0x8d, 0xf2, 0xd7, 0xaf, 0x6a, 0x7e, 0x0c, 0xff, 0x4b, 0x4c, 0x2b, 0x70, 0x09, 0xfd, + 0x29, 0xe9, 0x95, 0x77, 0x87, 0x88, 0x0c, 0x61, 0x50, 0x63, 0x5b, 0xa1, 0x2b, 0xd3, 0x32, 0x36, + 0x1c, 0xa2, 0xe4, 0x03, 0xab, 0xd3, 0x33, 0xa9, 0xeb, 0xaf, 0x06, 0xb8, 0x13, 0x25, 0x25, 0xde, + 0x82, 0xbb, 0xda, 0x85, 0x83, 0xf1, 0xe6, 0x47, 0x8c, 0x0b, 0xdf, 0xc1, 0x67, 0xf5, 0x86, 0x4d, + 0xe0, 0x0e, 0x9a, 0x46, 0x1c, 0x4b, 0x94, 0x62, 0x9e, 0xfe, 0x70, 0x4b, 0x67, 0x33, 0x6d, 0x7c, + 0x2e, 0x4f, 0x17, 0xa3, 0x28, 0x4f, 0x97, 0x42, 0xc1, 0x07, 0xe8, 0x14, 0xac, 0xc6, 0x93, 0x22, + 0xb3, 0x9e, 0x96, 0x7f, 0xba, 0xb3, 0x6f, 0xf5, 0x1e, 0xa1, 0x57, 0x71, 0x1d, 0x79, 0x65, 0x66, + 0x4b, 0x80, 0xfe, 0xd9, 0x5e, 0x8e, 0xd5, 0x7e, 0x82, 0x7f, 0xd5, 0x1c, 0xb0, 0x3a, 0xb8, 0x2d, + 0x54, 0xff, 0x7c, 0x3f, 0x29, 0x93, 0x7f, 0x6e, 0x99, 0xfe, 0xcd, 0x77, 0x00, 0x00, 0x00, 0xff, + 0xff, 0x4b, 0x17, 0x4b, 0x65, 0xe0, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -557,7 +558,7 @@ func NewConnClient(cc grpc.ClientConnInterface) ConnClient { func (c *connClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) { out := new(ReadResponse) - err := c.cc.Invoke(ctx, "/proto.Conn/Read", in, out, opts...) + err := c.cc.Invoke(ctx, "/gconnproto.Conn/Read", in, out, opts...) if err != nil { return nil, err } @@ -566,7 +567,7 @@ func (c *connClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.Cal func (c *connClient) Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) { out := new(WriteResponse) - err := c.cc.Invoke(ctx, "/proto.Conn/Write", in, out, opts...) + err := c.cc.Invoke(ctx, "/gconnproto.Conn/Write", in, out, opts...) if err != nil { return nil, err } @@ -575,7 +576,7 @@ func (c *connClient) Write(ctx context.Context, in *WriteRequest, opts ...grpc.C func (c *connClient) Close(ctx context.Context, in *CloseRequest, opts ...grpc.CallOption) (*CloseResponse, error) { out := new(CloseResponse) - err := c.cc.Invoke(ctx, "/proto.Conn/Close", in, out, opts...) + err := c.cc.Invoke(ctx, "/gconnproto.Conn/Close", in, out, opts...) if err != nil { return nil, err } @@ -584,7 +585,7 @@ func (c *connClient) Close(ctx context.Context, in *CloseRequest, opts ...grpc.C func (c *connClient) SetDeadline(ctx context.Context, in *SetDeadlineRequest, opts ...grpc.CallOption) (*SetDeadlineResponse, error) { out := new(SetDeadlineResponse) - err := c.cc.Invoke(ctx, "/proto.Conn/SetDeadline", in, out, opts...) + err := c.cc.Invoke(ctx, "/gconnproto.Conn/SetDeadline", in, out, opts...) if err != nil { return nil, err } @@ -593,7 +594,7 @@ func (c *connClient) SetDeadline(ctx context.Context, in *SetDeadlineRequest, op func (c *connClient) SetReadDeadline(ctx context.Context, in *SetReadDeadlineRequest, opts ...grpc.CallOption) (*SetReadDeadlineResponse, error) { out := new(SetReadDeadlineResponse) - err := c.cc.Invoke(ctx, "/proto.Conn/SetReadDeadline", in, out, opts...) + err := c.cc.Invoke(ctx, "/gconnproto.Conn/SetReadDeadline", in, out, opts...) if err != nil { return nil, err } @@ -602,7 +603,7 @@ func (c *connClient) SetReadDeadline(ctx context.Context, in *SetReadDeadlineReq func (c *connClient) SetWriteDeadline(ctx context.Context, in *SetWriteDeadlineRequest, opts ...grpc.CallOption) (*SetWriteDeadlineResponse, error) { out := new(SetWriteDeadlineResponse) - err := c.cc.Invoke(ctx, "/proto.Conn/SetWriteDeadline", in, out, opts...) + err := c.cc.Invoke(ctx, "/gconnproto.Conn/SetWriteDeadline", in, out, opts...) if err != nil { return nil, err } @@ -656,7 +657,7 @@ func _Conn_Read_Handler(srv interface{}, ctx context.Context, dec func(interface } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Conn/Read", + FullMethod: "/gconnproto.Conn/Read", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ConnServer).Read(ctx, req.(*ReadRequest)) @@ -674,7 +675,7 @@ func _Conn_Write_Handler(srv interface{}, ctx context.Context, dec func(interfac } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Conn/Write", + FullMethod: "/gconnproto.Conn/Write", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ConnServer).Write(ctx, req.(*WriteRequest)) @@ -692,7 +693,7 @@ func _Conn_Close_Handler(srv interface{}, ctx context.Context, dec func(interfac } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Conn/Close", + FullMethod: "/gconnproto.Conn/Close", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ConnServer).Close(ctx, req.(*CloseRequest)) @@ -710,7 +711,7 @@ func _Conn_SetDeadline_Handler(srv interface{}, ctx context.Context, dec func(in } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Conn/SetDeadline", + FullMethod: "/gconnproto.Conn/SetDeadline", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ConnServer).SetDeadline(ctx, req.(*SetDeadlineRequest)) @@ -728,7 +729,7 @@ func _Conn_SetReadDeadline_Handler(srv interface{}, ctx context.Context, dec fun } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Conn/SetReadDeadline", + FullMethod: "/gconnproto.Conn/SetReadDeadline", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ConnServer).SetReadDeadline(ctx, req.(*SetReadDeadlineRequest)) @@ -746,7 +747,7 @@ func _Conn_SetWriteDeadline_Handler(srv interface{}, ctx context.Context, dec fu } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Conn/SetWriteDeadline", + FullMethod: "/gconnproto.Conn/SetWriteDeadline", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ConnServer).SetWriteDeadline(ctx, req.(*SetWriteDeadlineRequest)) @@ -755,7 +756,7 @@ func _Conn_SetWriteDeadline_Handler(srv interface{}, ctx context.Context, dec fu } var _Conn_serviceDesc = grpc.ServiceDesc{ - ServiceName: "proto.Conn", + ServiceName: "gconnproto.Conn", HandlerType: (*ConnServer)(nil), Methods: []grpc.MethodDesc{ { @@ -784,5 +785,5 @@ var _Conn_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "conn.proto", + Metadata: "gconn.proto", } diff --git a/vms/rpcchainvm/ghttp/gconn/proto/conn.proto b/vms/rpcchainvm/ghttp/gconn/gconnproto/gconn.proto similarity index 98% rename from vms/rpcchainvm/ghttp/gconn/proto/conn.proto rename to vms/rpcchainvm/ghttp/gconn/gconnproto/gconn.proto index cc5d150..f749f38 100644 --- a/vms/rpcchainvm/ghttp/gconn/proto/conn.proto +++ b/vms/rpcchainvm/ghttp/gconn/gconnproto/gconn.proto @@ -1,5 +1,5 @@ syntax = "proto3"; -package proto; +package gconnproto; message ReadRequest { int32 length = 1; diff --git a/vms/rpcchainvm/ghttp/proto/http.pb.go b/vms/rpcchainvm/ghttp/ghttpproto/ghttp.pb.go similarity index 76% rename from vms/rpcchainvm/ghttp/proto/http.pb.go rename to vms/rpcchainvm/ghttp/ghttpproto/ghttp.pb.go index 013c3b4..b88abaa 100644 --- a/vms/rpcchainvm/ghttp/proto/http.pb.go +++ b/vms/rpcchainvm/ghttp/ghttpproto/ghttp.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: http.proto +// source: ghttp.proto -package proto +package ghttpproto import ( context "context" @@ -37,7 +37,7 @@ func (m *Userinfo) Reset() { *m = Userinfo{} } func (m *Userinfo) String() string { return proto.CompactTextString(m) } func (*Userinfo) ProtoMessage() {} func (*Userinfo) Descriptor() ([]byte, []int) { - return fileDescriptor_11b04836674e6f94, []int{0} + return fileDescriptor_e26bba3d5e69055f, []int{0} } func (m *Userinfo) XXX_Unmarshal(b []byte) error { @@ -98,7 +98,7 @@ func (m *URL) Reset() { *m = URL{} } func (m *URL) String() string { return proto.CompactTextString(m) } func (*URL) ProtoMessage() {} func (*URL) Descriptor() ([]byte, []int) { - return fileDescriptor_11b04836674e6f94, []int{1} + return fileDescriptor_e26bba3d5e69055f, []int{1} } func (m *URL) XXX_Unmarshal(b []byte) error { @@ -194,7 +194,7 @@ func (m *Element) Reset() { *m = Element{} } func (m *Element) String() string { return proto.CompactTextString(m) } func (*Element) ProtoMessage() {} func (*Element) Descriptor() ([]byte, []int) { - return fileDescriptor_11b04836674e6f94, []int{2} + return fileDescriptor_e26bba3d5e69055f, []int{2} } func (m *Element) XXX_Unmarshal(b []byte) error { @@ -240,7 +240,7 @@ func (m *Certificates) Reset() { *m = Certificates{} } func (m *Certificates) String() string { return proto.CompactTextString(m) } func (*Certificates) ProtoMessage() {} func (*Certificates) Descriptor() ([]byte, []int) { - return fileDescriptor_11b04836674e6f94, []int{3} + return fileDescriptor_e26bba3d5e69055f, []int{3} } func (m *Certificates) XXX_Unmarshal(b []byte) error { @@ -290,7 +290,7 @@ func (m *ConnectionState) Reset() { *m = ConnectionState{} } func (m *ConnectionState) String() string { return proto.CompactTextString(m) } func (*ConnectionState) ProtoMessage() {} func (*ConnectionState) Descriptor() ([]byte, []int) { - return fileDescriptor_11b04836674e6f94, []int{4} + return fileDescriptor_e26bba3d5e69055f, []int{4} } func (m *ConnectionState) XXX_Unmarshal(b []byte) error { @@ -421,7 +421,7 @@ func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_11b04836674e6f94, []int{5} + return fileDescriptor_e26bba3d5e69055f, []int{5} } func (m *Request) XXX_Unmarshal(b []byte) error { @@ -566,7 +566,7 @@ func (m *HTTPRequest) Reset() { *m = HTTPRequest{} } func (m *HTTPRequest) String() string { return proto.CompactTextString(m) } func (*HTTPRequest) ProtoMessage() {} func (*HTTPRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11b04836674e6f94, []int{6} + return fileDescriptor_e26bba3d5e69055f, []int{6} } func (m *HTTPRequest) XXX_Unmarshal(b []byte) error { @@ -611,7 +611,7 @@ func (m *HTTPResponse) Reset() { *m = HTTPResponse{} } func (m *HTTPResponse) String() string { return proto.CompactTextString(m) } func (*HTTPResponse) ProtoMessage() {} func (*HTTPResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11b04836674e6f94, []int{7} + return fileDescriptor_e26bba3d5e69055f, []int{7} } func (m *HTTPResponse) XXX_Unmarshal(b []byte) error { @@ -633,71 +633,72 @@ func (m *HTTPResponse) XXX_DiscardUnknown() { var xxx_messageInfo_HTTPResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*Userinfo)(nil), "proto.Userinfo") - proto.RegisterType((*URL)(nil), "proto.URL") - proto.RegisterType((*Element)(nil), "proto.Element") - proto.RegisterType((*Certificates)(nil), "proto.Certificates") - proto.RegisterType((*ConnectionState)(nil), "proto.ConnectionState") - proto.RegisterType((*Request)(nil), "proto.Request") - proto.RegisterType((*HTTPRequest)(nil), "proto.HTTPRequest") - proto.RegisterType((*HTTPResponse)(nil), "proto.HTTPResponse") + proto.RegisterType((*Userinfo)(nil), "ghttpproto.Userinfo") + proto.RegisterType((*URL)(nil), "ghttpproto.URL") + proto.RegisterType((*Element)(nil), "ghttpproto.Element") + proto.RegisterType((*Certificates)(nil), "ghttpproto.Certificates") + proto.RegisterType((*ConnectionState)(nil), "ghttpproto.ConnectionState") + proto.RegisterType((*Request)(nil), "ghttpproto.Request") + proto.RegisterType((*HTTPRequest)(nil), "ghttpproto.HTTPRequest") + proto.RegisterType((*HTTPResponse)(nil), "ghttpproto.HTTPResponse") } -func init() { proto.RegisterFile("http.proto", fileDescriptor_11b04836674e6f94) } +func init() { proto.RegisterFile("ghttp.proto", fileDescriptor_e26bba3d5e69055f) } -var fileDescriptor_11b04836674e6f94 = []byte{ - // 816 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x54, 0xdb, 0x6e, 0x1b, 0x37, - 0x10, 0x85, 0xb2, 0xb2, 0x2e, 0xa3, 0x8b, 0x5d, 0xa6, 0x08, 0x08, 0x37, 0x28, 0x84, 0x6d, 0x11, - 0x08, 0x41, 0x61, 0xa0, 0xce, 0x53, 0x51, 0xa0, 0x17, 0x18, 0x29, 0x12, 0xd4, 0x29, 0x5c, 0xda, - 0x46, 0x1f, 0x0b, 0x66, 0x77, 0xa4, 0x65, 0xb3, 0x4b, 0x6e, 0x48, 0xae, 0x0c, 0x7f, 0x47, 0x3f, - 0xa3, 0xbf, 0xd7, 0x0f, 0x28, 0x78, 0x59, 0x69, 0x15, 0xb9, 0x7e, 0xda, 0x99, 0x73, 0x86, 0xcb, - 0x99, 0x39, 0x33, 0x04, 0x28, 0xac, 0xad, 0xcf, 0x6a, 0xad, 0xac, 0x22, 0x47, 0xfe, 0x93, 0xe6, - 0x30, 0xba, 0x35, 0xa8, 0x85, 0x5c, 0x29, 0x72, 0x0a, 0xa3, 0xc6, 0xa0, 0x96, 0xbc, 0x42, 0xda, - 0x5b, 0xf4, 0x96, 0x63, 0xb6, 0xf5, 0x1d, 0x57, 0x73, 0x63, 0xee, 0x94, 0xce, 0xe9, 0x93, 0xc0, - 0xb5, 0x3e, 0x59, 0xc0, 0xa4, 0xb5, 0xaf, 0xd1, 0xd2, 0x64, 0xd1, 0x5b, 0x8e, 0x58, 0x17, 0x4a, - 0xff, 0xed, 0x41, 0x72, 0xcb, 0x2e, 0xc9, 0x33, 0x18, 0x98, 0xac, 0xc0, 0xed, 0xff, 0xa3, 0xe7, - 0x70, 0x55, 0xf3, 0x8f, 0x0d, 0xc6, 0x7f, 0x47, 0x8f, 0x7c, 0x05, 0x7d, 0x97, 0x81, 0xff, 0xe5, - 0xe4, 0xfc, 0x38, 0xa4, 0x7e, 0xd6, 0x26, 0xcc, 0x3c, 0x49, 0x08, 0xf4, 0x0b, 0x65, 0x2c, 0xed, - 0xfb, 0xa3, 0xde, 0x76, 0x58, 0xcd, 0x6d, 0x41, 0x8f, 0x02, 0xe6, 0x6c, 0x42, 0x61, 0xa8, 0xf9, - 0xdd, 0x95, 0x83, 0x07, 0x1e, 0x6e, 0x5d, 0xf2, 0x25, 0xc0, 0x4a, 0xe9, 0x0c, 0x7f, 0x6f, 0x50, - 0xdf, 0xd3, 0xa1, 0xcf, 0xbf, 0x83, 0xb8, 0xe2, 0x35, 0xbf, 0x0b, 0xec, 0x28, 0x14, 0xdf, 0xfa, - 0x8e, 0x5b, 0x69, 0xbe, 0xae, 0x50, 0x5a, 0x3a, 0x0e, 0x5c, 0xeb, 0xa7, 0xaf, 0x60, 0xf8, 0xba, - 0x44, 0x67, 0x92, 0x13, 0x48, 0x3e, 0xe0, 0x7d, 0x2c, 0xdb, 0x99, 0xae, 0xe6, 0x0d, 0x2f, 0x1b, - 0x34, 0xf4, 0xc9, 0x22, 0x71, 0x35, 0x07, 0x2f, 0x4d, 0x61, 0x7a, 0x81, 0xda, 0x8a, 0x95, 0xc8, - 0xb8, 0x45, 0xe3, 0x4a, 0xc9, 0x50, 0x5b, 0xda, 0x5b, 0x24, 0xcb, 0x29, 0xf3, 0x76, 0xfa, 0x4f, - 0x1f, 0x8e, 0x2f, 0x94, 0x94, 0x98, 0x59, 0xa1, 0xe4, 0xb5, 0xe5, 0x16, 0x5d, 0x79, 0x1b, 0xd4, - 0x46, 0x28, 0xe9, 0x6f, 0x99, 0xb1, 0xd6, 0x25, 0xdf, 0xc0, 0x67, 0x05, 0x97, 0xb9, 0x29, 0xf8, - 0x07, 0xbc, 0x50, 0x55, 0x5d, 0xa2, 0x0d, 0x8d, 0x1e, 0xb1, 0x43, 0x82, 0x3c, 0x87, 0x71, 0x2e, - 0x72, 0x86, 0xa6, 0xa9, 0x30, 0x6a, 0xb9, 0x03, 0x9c, 0xd6, 0x99, 0xa8, 0x0b, 0xd4, 0xd7, 0x8d, - 0xb0, 0xe8, 0x7b, 0x3e, 0x63, 0x5d, 0x88, 0x9c, 0x01, 0x91, 0xb8, 0x56, 0x56, 0x70, 0x8b, 0xf9, - 0x95, 0x13, 0x2c, 0x53, 0x65, 0x14, 0xe2, 0x01, 0x86, 0xfc, 0x00, 0xa7, 0x87, 0xe8, 0x5b, 0xf3, - 0xae, 0xb1, 0x0d, 0x2f, 0xbd, 0x52, 0x23, 0xf6, 0x48, 0x84, 0x13, 0xcf, 0xa0, 0xde, 0xa0, 0xfe, - 0xcd, 0xcd, 0xed, 0xd0, 0xdf, 0xd3, 0x41, 0xc8, 0x8f, 0x70, 0x52, 0x23, 0xea, 0x6e, 0x4f, 0xbd, - 0x88, 0x93, 0xf3, 0xa7, 0x71, 0x9e, 0xba, 0x14, 0x3b, 0x08, 0x26, 0xdf, 0xc3, 0x7c, 0x83, 0x5a, - 0xac, 0x04, 0xe6, 0x17, 0x05, 0x17, 0xd2, 0xd0, 0xf1, 0x22, 0xf9, 0xbf, 0xe3, 0x9f, 0x84, 0x92, - 0x9f, 0xe0, 0x0b, 0x23, 0xd6, 0x12, 0xf3, 0x4e, 0xd4, 0x8d, 0xa8, 0xd0, 0x58, 0x5e, 0xd5, 0x86, - 0x82, 0x17, 0xf5, 0xb1, 0x10, 0x92, 0xc2, 0x54, 0x65, 0xa6, 0x66, 0x68, 0x6a, 0x25, 0x0d, 0xd2, - 0xc9, 0xa2, 0xb7, 0x9c, 0xb2, 0x3d, 0xcc, 0x69, 0x66, 0x4b, 0x73, 0x2b, 0x85, 0x5b, 0xa1, 0xa9, - 0x0f, 0xd8, 0x01, 0xe9, 0xdf, 0x7d, 0x18, 0x32, 0xfc, 0xd8, 0xa0, 0xb1, 0x6e, 0xea, 0x2a, 0xb4, - 0x85, 0xca, 0xdb, 0x0d, 0x0c, 0x1e, 0x79, 0x0e, 0x49, 0xa3, 0x4b, 0x3f, 0x15, 0x93, 0x73, 0x68, - 0x17, 0x8d, 0x5d, 0x32, 0x07, 0x93, 0xcf, 0x21, 0x3c, 0x17, 0x7e, 0x1e, 0xc6, 0x2c, 0x38, 0xae, - 0xf3, 0xde, 0x78, 0xc7, 0xff, 0x52, 0xda, 0x8f, 0xc2, 0x11, 0xeb, 0x20, 0x3b, 0x5e, 0x48, 0xa5, - 0xfd, 0x04, 0x6c, 0x79, 0x87, 0x90, 0x17, 0x30, 0x28, 0x90, 0xe7, 0xa8, 0xe9, 0xc0, 0x37, 0x74, - 0x1e, 0xaf, 0x8d, 0x3b, 0xc3, 0x22, 0xeb, 0x36, 0xe0, 0xbd, 0xca, 0xc3, 0x62, 0xce, 0x98, 0xb7, - 0xc9, 0xd7, 0x30, 0xcb, 0x94, 0xb4, 0x28, 0xed, 0x25, 0xca, 0xb5, 0x2d, 0xbc, 0xa4, 0x09, 0xdb, - 0x07, 0xc9, 0x4b, 0x38, 0xb1, 0x9a, 0x4b, 0xb3, 0x42, 0xfd, 0x5a, 0x66, 0x2a, 0x17, 0x72, 0xed, - 0xc5, 0x1b, 0xb3, 0x03, 0x7c, 0xfb, 0x8c, 0x40, 0xe7, 0x19, 0x49, 0xa1, 0xbf, 0x52, 0xba, 0xa2, - 0x93, 0x07, 0xf3, 0xf3, 0x1c, 0x79, 0x09, 0xa3, 0x5a, 0x19, 0xfb, 0x8b, 0x8b, 0x9b, 0x3e, 0x18, - 0xb7, 0xe5, 0xdd, 0xf6, 0x58, 0xcd, 0x45, 0x89, 0xfa, 0x57, 0xbc, 0x37, 0x74, 0xe6, 0x53, 0xe9, - 0x42, 0xae, 0x67, 0x1a, 0x2b, 0x65, 0xf1, 0xe7, 0x3c, 0xd7, 0x74, 0x1e, 0xa6, 0x79, 0x87, 0x04, - 0xde, 0x4b, 0x79, 0xcb, 0xde, 0xd2, 0xe3, 0x96, 0x6f, 0x11, 0xb2, 0x84, 0xc4, 0x96, 0x86, 0x9e, - 0x78, 0x1d, 0x9f, 0xb5, 0x13, 0xba, 0xff, 0x54, 0x30, 0x17, 0x92, 0xfe, 0x09, 0x93, 0x37, 0x37, - 0x37, 0x57, 0xed, 0x60, 0xbc, 0x80, 0xb9, 0x8e, 0xe3, 0xf4, 0x87, 0x16, 0x16, 0x75, 0x7c, 0x45, - 0x3e, 0x41, 0xc9, 0x12, 0x86, 0xf1, 0xba, 0x38, 0x2c, 0x6d, 0xb5, 0xf1, 0x47, 0xac, 0xa5, 0xd3, - 0x39, 0x4c, 0xc3, 0x05, 0xe1, 0xfc, 0xf9, 0x77, 0xd0, 0x77, 0x3e, 0xf9, 0x16, 0x06, 0x6f, 0xb8, - 0xcc, 0x4b, 0x24, 0x24, 0x1e, 0xed, 0xe4, 0x71, 0xfa, 0x74, 0x0f, 0x0b, 0x47, 0xdf, 0x0f, 0x3c, - 0xf6, 0xea, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xbf, 0x29, 0xb2, 0xd4, 0xc1, 0x06, 0x00, 0x00, +var fileDescriptor_e26bba3d5e69055f = []byte{ + // 819 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x54, 0xdf, 0x8f, 0x1b, 0x35, + 0x10, 0x56, 0xba, 0xb9, 0xfc, 0x98, 0x4d, 0xee, 0x0e, 0x53, 0x81, 0x75, 0x45, 0x28, 0xac, 0x10, + 0x44, 0x40, 0x0f, 0x29, 0x7d, 0x44, 0x42, 0x45, 0xa1, 0xa8, 0x15, 0x57, 0x74, 0xf8, 0x2e, 0xe2, + 0xd9, 0x5d, 0x4f, 0xb2, 0xa6, 0xbb, 0xf6, 0xd6, 0xf6, 0xe6, 0x74, 0xff, 0x13, 0xaf, 0xfc, 0x71, + 0xbc, 0x21, 0x7b, 0x77, 0x93, 0x4d, 0xd3, 0xde, 0xdb, 0xcc, 0xf7, 0x8d, 0xc7, 0x9e, 0xf9, 0x66, + 0x0c, 0xf1, 0x26, 0x73, 0xae, 0xbc, 0x2c, 0x8d, 0x76, 0x9a, 0x40, 0x70, 0x82, 0x9d, 0x08, 0x18, + 0xad, 0x2c, 0x1a, 0xa9, 0xd6, 0x9a, 0x5c, 0xc0, 0xa8, 0xb2, 0x68, 0x14, 0x2f, 0x90, 0xf6, 0x66, + 0xbd, 0xf9, 0x98, 0xed, 0x7c, 0xcf, 0x95, 0xdc, 0xda, 0x3b, 0x6d, 0x04, 0x7d, 0x54, 0x73, 0xad, + 0x4f, 0x66, 0x10, 0xb7, 0xf6, 0x0d, 0x3a, 0x1a, 0xcd, 0x7a, 0xf3, 0x11, 0xeb, 0x42, 0xc9, 0x7f, + 0x3d, 0x88, 0x56, 0xec, 0x8a, 0x7c, 0x06, 0x03, 0x9b, 0x66, 0xb8, 0xcb, 0xdf, 0x78, 0x1e, 0xd7, + 0x25, 0x7f, 0x57, 0x61, 0x93, 0xbb, 0xf1, 0xc8, 0x1c, 0xfa, 0xfe, 0x05, 0x21, 0x65, 0xbc, 0x78, + 0x7c, 0xb9, 0x7f, 0xf8, 0x65, 0xfb, 0x6a, 0x16, 0x22, 0x08, 0x81, 0x7e, 0xa6, 0xad, 0xa3, 0xfd, + 0x70, 0x3e, 0xd8, 0x1e, 0x2b, 0xb9, 0xcb, 0xe8, 0x49, 0x8d, 0x79, 0x9b, 0x50, 0x18, 0x1a, 0x7e, + 0x77, 0xed, 0xe1, 0x41, 0x80, 0x5b, 0x97, 0x7c, 0x09, 0xb0, 0xd6, 0x26, 0xc5, 0x3f, 0x2b, 0x34, + 0xf7, 0x74, 0x18, 0x8a, 0xe8, 0x20, 0xbe, 0x03, 0x86, 0xdf, 0xd5, 0xec, 0xa8, 0xee, 0x40, 0xeb, + 0x7b, 0x6e, 0x6d, 0xf8, 0xa6, 0x40, 0xe5, 0xe8, 0xb8, 0xe6, 0x5a, 0x3f, 0x79, 0x06, 0xc3, 0x17, + 0x39, 0x7a, 0x93, 0x9c, 0x43, 0xf4, 0x16, 0xef, 0x9b, 0xda, 0xbd, 0xe9, 0x0b, 0xdf, 0xf2, 0xbc, + 0x42, 0x4b, 0x1f, 0xcd, 0x22, 0x5f, 0x78, 0xed, 0x25, 0x09, 0x4c, 0x96, 0x68, 0x9c, 0x5c, 0xcb, + 0x94, 0x3b, 0xb4, 0xbe, 0x94, 0x14, 0x8d, 0xa3, 0xbd, 0x59, 0x34, 0x9f, 0xb0, 0x60, 0x27, 0xff, + 0xf6, 0xe1, 0x6c, 0xa9, 0x95, 0xc2, 0xd4, 0x49, 0xad, 0x6e, 0x1c, 0x77, 0xe8, 0xcb, 0xdb, 0xa2, + 0xb1, 0x52, 0xab, 0x70, 0xcb, 0x94, 0xb5, 0x2e, 0xf9, 0x01, 0x3e, 0xc9, 0xb8, 0x12, 0x36, 0xe3, + 0x6f, 0x71, 0xa9, 0x8b, 0x32, 0x47, 0x57, 0x77, 0x7b, 0xc4, 0x8e, 0x09, 0xf2, 0x05, 0x8c, 0x85, + 0x14, 0x0c, 0x6d, 0x55, 0x60, 0x23, 0xe8, 0x1e, 0xf0, 0x82, 0xa7, 0xb2, 0xcc, 0xd0, 0xdc, 0x54, + 0xd2, 0x61, 0xe8, 0xf9, 0x94, 0x75, 0x21, 0x72, 0x09, 0x44, 0xe1, 0x46, 0x3b, 0xc9, 0x1d, 0x8a, + 0x6b, 0x2f, 0x58, 0xaa, 0xf3, 0x46, 0x88, 0x0f, 0x30, 0xe4, 0x67, 0xb8, 0x38, 0x46, 0x5f, 0xd9, + 0xd7, 0x95, 0xab, 0x78, 0x1e, 0x94, 0x1a, 0xb1, 0x07, 0x22, 0xbc, 0x78, 0x16, 0xcd, 0x16, 0xcd, + 0x1f, 0x7e, 0x78, 0x87, 0xe1, 0x9e, 0x0e, 0x42, 0x7e, 0x85, 0xf3, 0x12, 0xd1, 0x74, 0x7b, 0x1a, + 0x44, 0x8c, 0x17, 0xb4, 0x3b, 0x54, 0x5d, 0x9e, 0x1d, 0x9d, 0x20, 0xcf, 0xe1, 0x74, 0x8b, 0x46, + 0xae, 0x25, 0x8a, 0x65, 0xc6, 0xa5, 0xb2, 0x74, 0x3c, 0x8b, 0x1e, 0xcc, 0xf1, 0x5e, 0x3c, 0x79, + 0x0e, 0x4f, 0xac, 0xdc, 0x28, 0x14, 0x9d, 0xa8, 0x5b, 0x59, 0xa0, 0x75, 0xbc, 0x28, 0x2d, 0x85, + 0x20, 0xef, 0x43, 0x21, 0x24, 0x81, 0x89, 0x4e, 0x6d, 0xc9, 0xd0, 0x96, 0x5a, 0x59, 0xa4, 0xf1, + 0xac, 0x37, 0x9f, 0xb0, 0x03, 0xcc, 0xab, 0xe7, 0x72, 0xbb, 0x52, 0xd2, 0x6f, 0xd4, 0x24, 0x04, + 0xec, 0x81, 0xe4, 0x9f, 0x3e, 0x0c, 0x19, 0xbe, 0xab, 0xd0, 0x3a, 0x3f, 0x7f, 0x05, 0xba, 0x4c, + 0x8b, 0x76, 0x21, 0x6b, 0x8f, 0x7c, 0x05, 0x51, 0x65, 0xf2, 0x30, 0x1f, 0xf1, 0xe2, 0xec, 0x60, + 0xef, 0xd8, 0x15, 0xf3, 0x1c, 0x79, 0x0c, 0x27, 0x01, 0x09, 0xe3, 0x31, 0x66, 0xb5, 0xe3, 0x85, + 0x08, 0xc6, 0x6b, 0xfe, 0xb7, 0x36, 0x61, 0x32, 0x4e, 0x58, 0x07, 0xd9, 0xf3, 0x52, 0x69, 0x13, + 0x06, 0x62, 0xc7, 0x7b, 0x84, 0x7c, 0x0f, 0x83, 0x0c, 0xb9, 0x40, 0x43, 0x07, 0xa1, 0xb5, 0x9f, + 0x76, 0xef, 0x6e, 0xf6, 0x88, 0x35, 0x21, 0x7e, 0x2b, 0xde, 0x68, 0x51, 0x2f, 0xeb, 0x94, 0x05, + 0x9b, 0x7c, 0x0d, 0xd3, 0x54, 0x2b, 0x87, 0xca, 0x5d, 0xa1, 0xda, 0xb8, 0x2c, 0xc8, 0x1c, 0xb1, + 0x43, 0x90, 0x7c, 0x07, 0xe7, 0xce, 0x70, 0x65, 0xd7, 0x68, 0x5e, 0xa8, 0x54, 0x0b, 0xa9, 0x36, + 0x41, 0xcb, 0x31, 0x3b, 0xc2, 0x77, 0x5f, 0x0b, 0x74, 0xbe, 0x96, 0x6f, 0xa1, 0xbf, 0xd6, 0xa6, + 0xa0, 0xf1, 0xc7, 0x1f, 0x19, 0x02, 0xc8, 0x8f, 0x30, 0x2a, 0xb5, 0x75, 0xbf, 0xf9, 0xe0, 0xc9, + 0xc7, 0x83, 0x77, 0x41, 0x7e, 0xb7, 0x9c, 0xe1, 0x32, 0x47, 0xf3, 0x3b, 0xde, 0x5b, 0x3a, 0x0d, + 0x8f, 0xea, 0x42, 0xbe, 0x85, 0x06, 0x0b, 0xed, 0xf0, 0x17, 0x21, 0x0c, 0x3d, 0xad, 0x67, 0x7d, + 0x8f, 0xd4, 0x7c, 0x90, 0x77, 0xc5, 0x5e, 0xd1, 0xb3, 0x96, 0x6f, 0x11, 0xf2, 0x14, 0x22, 0x97, + 0x5b, 0x7a, 0x1e, 0xb4, 0x7d, 0x72, 0x30, 0xba, 0x87, 0xbf, 0x09, 0xf3, 0x71, 0x89, 0x80, 0xf8, + 0xe5, 0xed, 0xed, 0x75, 0x3b, 0x31, 0xdf, 0xc0, 0xa9, 0x69, 0xe6, 0xec, 0x2f, 0x23, 0x1d, 0x9a, + 0xe6, 0xa3, 0x79, 0x0f, 0x25, 0x4f, 0x61, 0xd8, 0xdc, 0xd9, 0x4c, 0xd1, 0x41, 0xdd, 0x4d, 0x36, + 0xd6, 0xc6, 0x24, 0xa7, 0x30, 0xa9, 0x6f, 0xa9, 0x93, 0x2c, 0x96, 0xd0, 0xf7, 0x3e, 0xf9, 0x09, + 0x06, 0x2f, 0xb9, 0x12, 0x39, 0x92, 0xcf, 0xbb, 0xe7, 0x3b, 0x2f, 0xba, 0xa0, 0xc7, 0x44, 0x9d, + 0xe4, 0xcd, 0x20, 0x60, 0xcf, 0xfe, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x42, 0xa3, 0x7e, 0xab, 0xfe, + 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -725,7 +726,7 @@ func NewHTTPClient(cc grpc.ClientConnInterface) HTTPClient { func (c *hTTPClient) Handle(ctx context.Context, in *HTTPRequest, opts ...grpc.CallOption) (*HTTPResponse, error) { out := new(HTTPResponse) - err := c.cc.Invoke(ctx, "/proto.HTTP/Handle", in, out, opts...) + err := c.cc.Invoke(ctx, "/ghttpproto.HTTP/Handle", in, out, opts...) if err != nil { return nil, err } @@ -759,7 +760,7 @@ func _HTTP_Handle_Handler(srv interface{}, ctx context.Context, dec func(interfa } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.HTTP/Handle", + FullMethod: "/ghttpproto.HTTP/Handle", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(HTTPServer).Handle(ctx, req.(*HTTPRequest)) @@ -768,7 +769,7 @@ func _HTTP_Handle_Handler(srv interface{}, ctx context.Context, dec func(interfa } var _HTTP_serviceDesc = grpc.ServiceDesc{ - ServiceName: "proto.HTTP", + ServiceName: "ghttpproto.HTTP", HandlerType: (*HTTPServer)(nil), Methods: []grpc.MethodDesc{ { @@ -777,5 +778,5 @@ var _HTTP_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "http.proto", + Metadata: "ghttp.proto", } diff --git a/vms/rpcchainvm/ghttp/proto/http.proto b/vms/rpcchainvm/ghttp/ghttpproto/ghttp.proto similarity index 98% rename from vms/rpcchainvm/ghttp/proto/http.proto rename to vms/rpcchainvm/ghttp/ghttpproto/ghttp.proto index f5e9c71..21a34e6 100644 --- a/vms/rpcchainvm/ghttp/proto/http.proto +++ b/vms/rpcchainvm/ghttp/ghttpproto/ghttp.proto @@ -1,6 +1,5 @@ syntax = "proto3"; -package proto; - +package ghttpproto; message Userinfo { string username = 1; diff --git a/vms/rpcchainvm/ghttp/greadcloser/proto/reader.pb.go b/vms/rpcchainvm/ghttp/greadcloser/greadcloserproto/greadcloser.pb.go similarity index 79% rename from vms/rpcchainvm/ghttp/greadcloser/proto/reader.pb.go rename to vms/rpcchainvm/ghttp/greadcloser/greadcloserproto/greadcloser.pb.go index 682a2e1..01b49f5 100644 --- a/vms/rpcchainvm/ghttp/greadcloser/proto/reader.pb.go +++ b/vms/rpcchainvm/ghttp/greadcloser/greadcloserproto/greadcloser.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: reader.proto +// source: greadcloser.proto -package proto +package greadcloserproto import ( context "context" @@ -35,7 +35,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f534e48276761a43, []int{0} + return fileDescriptor_21bd394eba12f5e9, []int{0} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -76,7 +76,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f534e48276761a43, []int{1} + return fileDescriptor_21bd394eba12f5e9, []int{1} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -128,7 +128,7 @@ func (m *CloseRequest) Reset() { *m = CloseRequest{} } func (m *CloseRequest) String() string { return proto.CompactTextString(m) } func (*CloseRequest) ProtoMessage() {} func (*CloseRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f534e48276761a43, []int{2} + return fileDescriptor_21bd394eba12f5e9, []int{2} } func (m *CloseRequest) XXX_Unmarshal(b []byte) error { @@ -159,7 +159,7 @@ func (m *CloseResponse) Reset() { *m = CloseResponse{} } func (m *CloseResponse) String() string { return proto.CompactTextString(m) } func (*CloseResponse) ProtoMessage() {} func (*CloseResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f534e48276761a43, []int{3} + return fileDescriptor_21bd394eba12f5e9, []int{3} } func (m *CloseResponse) XXX_Unmarshal(b []byte) error { @@ -181,29 +181,29 @@ func (m *CloseResponse) XXX_DiscardUnknown() { var xxx_messageInfo_CloseResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*ReadRequest)(nil), "proto.ReadRequest") - proto.RegisterType((*ReadResponse)(nil), "proto.ReadResponse") - proto.RegisterType((*CloseRequest)(nil), "proto.CloseRequest") - proto.RegisterType((*CloseResponse)(nil), "proto.CloseResponse") + proto.RegisterType((*ReadRequest)(nil), "greadcloserproto.ReadRequest") + proto.RegisterType((*ReadResponse)(nil), "greadcloserproto.ReadResponse") + proto.RegisterType((*CloseRequest)(nil), "greadcloserproto.CloseRequest") + proto.RegisterType((*CloseResponse)(nil), "greadcloserproto.CloseResponse") } -func init() { proto.RegisterFile("reader.proto", fileDescriptor_f534e48276761a43) } +func init() { proto.RegisterFile("greadcloser.proto", fileDescriptor_21bd394eba12f5e9) } -var fileDescriptor_f534e48276761a43 = []byte{ - // 195 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x8e, 0xd1, 0x6a, 0x84, 0x30, - 0x10, 0x45, 0x49, 0x6b, 0x6c, 0x3b, 0x4d, 0x5b, 0x98, 0x4a, 0x09, 0x3e, 0x49, 0xa0, 0xe0, 0x93, - 0x0b, 0xee, 0x27, 0xec, 0x1f, 0xcc, 0x1f, 0xb8, 0x38, 0xec, 0x3e, 0xb8, 0xc6, 0x4d, 0xdc, 0xff, - 0x5f, 0x4c, 0x22, 0xe8, 0x53, 0xee, 0xbd, 0x99, 0x99, 0x7b, 0x40, 0x39, 0xee, 0x7a, 0x76, 0xcd, - 0xe4, 0xec, 0x6c, 0x51, 0x86, 0xc7, 0xfc, 0xc3, 0x27, 0x71, 0xd7, 0x13, 0xdf, 0x1f, 0xec, 0x67, - 0xfc, 0x83, 0x7c, 0xe0, 0xf1, 0x32, 0x5f, 0xb5, 0xa8, 0x44, 0x2d, 0x29, 0x39, 0x43, 0xa0, 0xe2, - 0x98, 0x9f, 0xec, 0xe8, 0x19, 0x11, 0xb2, 0xe5, 0x5a, 0x98, 0x52, 0x14, 0x34, 0x16, 0x20, 0xd9, - 0x39, 0xeb, 0xf4, 0x4b, 0x25, 0xea, 0x0f, 0x8a, 0x06, 0x35, 0xbc, 0x05, 0xc1, 0xbd, 0x7e, 0xad, - 0x44, 0xfd, 0x4e, 0xab, 0x35, 0xdf, 0xa0, 0x4e, 0x83, 0xf5, 0x9c, 0xba, 0xcd, 0x0f, 0x7c, 0x25, - 0x1f, 0x4b, 0xda, 0x1b, 0xe4, 0x14, 0x90, 0xf1, 0x00, 0xd9, 0xa2, 0x10, 0x23, 0x7c, 0xb3, 0x41, - 0x2e, 0x7f, 0x77, 0x59, 0xe2, 0x6b, 0x41, 0x86, 0x5b, 0xb8, 0xfe, 0x6e, 0x9b, 0xca, 0x62, 0x1f, - 0xc6, 0x9d, 0x73, 0x1e, 0xc2, 0xe3, 0x33, 0x00, 0x00, 0xff, 0xff, 0x47, 0x74, 0x81, 0x61, 0x28, - 0x01, 0x00, 0x00, +var fileDescriptor_21bd394eba12f5e9 = []byte{ + // 208 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x4f, 0xcb, 0x8a, 0xc2, 0x40, + 0x10, 0x64, 0x76, 0x93, 0xec, 0x6e, 0x6f, 0xf6, 0xd5, 0x2c, 0x32, 0x04, 0xd4, 0x30, 0x20, 0xe4, + 0x94, 0x83, 0x7e, 0x82, 0x08, 0x9e, 0xe7, 0x0f, 0xa2, 0x69, 0xe2, 0x21, 0x64, 0xe2, 0x4c, 0xfc, + 0x18, 0xff, 0x56, 0xe6, 0x21, 0x04, 0x31, 0xb7, 0xaa, 0xea, 0xa2, 0xaa, 0x1a, 0xfe, 0x1a, 0x4d, + 0x55, 0x7d, 0x6c, 0x95, 0x21, 0x5d, 0xf6, 0x5a, 0x0d, 0x0a, 0x7f, 0x47, 0x92, 0x53, 0xc4, 0x0a, + 0x3e, 0x25, 0x55, 0xb5, 0xa4, 0xf3, 0x85, 0xcc, 0x80, 0x33, 0x48, 0x5a, 0xea, 0x9a, 0xe1, 0xc4, + 0x59, 0xce, 0x8a, 0x58, 0x06, 0x26, 0x24, 0xa4, 0xde, 0x66, 0x7a, 0xd5, 0x19, 0x42, 0x84, 0xc8, + 0x26, 0x39, 0x57, 0x2a, 0x1d, 0xc6, 0x7f, 0x88, 0x49, 0x6b, 0xa5, 0xf9, 0x4b, 0xce, 0x8a, 0x0f, + 0xe9, 0x09, 0x72, 0x78, 0x73, 0x80, 0x6a, 0xfe, 0x9a, 0xb3, 0xe2, 0x5d, 0xde, 0xa9, 0xf8, 0x86, + 0x74, 0x6b, 0x97, 0x84, 0x6e, 0xf1, 0x03, 0x5f, 0x81, 0xfb, 0x92, 0xf5, 0x95, 0x41, 0x62, 0x5b, + 0x49, 0xe3, 0x0e, 0x22, 0x8b, 0x70, 0x5e, 0x3e, 0x7e, 0x50, 0x8e, 0xe6, 0x67, 0x8b, 0xa9, 0x73, + 0x98, 0xbd, 0x87, 0xd8, 0x55, 0xe0, 0x13, 0xe3, 0x78, 0x4b, 0xb6, 0x9c, 0xbc, 0xfb, 0xa4, 0x43, + 0xe2, 0xc4, 0xcd, 0x2d, 0x00, 0x00, 0xff, 0xff, 0x8e, 0xaf, 0xb3, 0x35, 0x65, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -232,7 +232,7 @@ func NewReaderClient(cc grpc.ClientConnInterface) ReaderClient { func (c *readerClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) { out := new(ReadResponse) - err := c.cc.Invoke(ctx, "/proto.Reader/Read", in, out, opts...) + err := c.cc.Invoke(ctx, "/greadcloserproto.Reader/Read", in, out, opts...) if err != nil { return nil, err } @@ -241,7 +241,7 @@ func (c *readerClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.C func (c *readerClient) Close(ctx context.Context, in *CloseRequest, opts ...grpc.CallOption) (*CloseResponse, error) { out := new(CloseResponse) - err := c.cc.Invoke(ctx, "/proto.Reader/Close", in, out, opts...) + err := c.cc.Invoke(ctx, "/greadcloserproto.Reader/Close", in, out, opts...) if err != nil { return nil, err } @@ -279,7 +279,7 @@ func _Reader_Read_Handler(srv interface{}, ctx context.Context, dec func(interfa } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Reader/Read", + FullMethod: "/greadcloserproto.Reader/Read", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ReaderServer).Read(ctx, req.(*ReadRequest)) @@ -297,7 +297,7 @@ func _Reader_Close_Handler(srv interface{}, ctx context.Context, dec func(interf } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Reader/Close", + FullMethod: "/greadcloserproto.Reader/Close", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ReaderServer).Close(ctx, req.(*CloseRequest)) @@ -306,7 +306,7 @@ func _Reader_Close_Handler(srv interface{}, ctx context.Context, dec func(interf } var _Reader_serviceDesc = grpc.ServiceDesc{ - ServiceName: "proto.Reader", + ServiceName: "greadcloserproto.Reader", HandlerType: (*ReaderServer)(nil), Methods: []grpc.MethodDesc{ { @@ -319,5 +319,5 @@ var _Reader_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "reader.proto", + Metadata: "greadcloser.proto", } diff --git a/vms/rpcchainvm/ghttp/greadcloser/proto/reader.proto b/vms/rpcchainvm/ghttp/greadcloser/greadcloserproto/greadcloser.proto similarity index 92% rename from vms/rpcchainvm/ghttp/greadcloser/proto/reader.proto rename to vms/rpcchainvm/ghttp/greadcloser/greadcloserproto/greadcloser.proto index 0b300b3..2c67e29 100644 --- a/vms/rpcchainvm/ghttp/greadcloser/proto/reader.proto +++ b/vms/rpcchainvm/ghttp/greadcloser/greadcloserproto/greadcloser.proto @@ -1,5 +1,5 @@ syntax = "proto3"; -package proto; +package greadcloserproto; message ReadRequest { int32 length = 1; diff --git a/vms/rpcchainvm/ghttp/greadcloser/reader_client.go b/vms/rpcchainvm/ghttp/greadcloser/reader_client.go index d5d139e..f828974 100644 --- a/vms/rpcchainvm/ghttp/greadcloser/reader_client.go +++ b/vms/rpcchainvm/ghttp/greadcloser/reader_client.go @@ -7,20 +7,20 @@ import ( "context" "errors" - "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greadcloser/proto" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greadcloser/greadcloserproto" ) // Client is an implementation of a messenger channel that talks over RPC. -type Client struct{ client proto.ReaderClient } +type Client struct{ client greadcloserproto.ReaderClient } // NewClient returns a database instance connected to a remote database instance -func NewClient(client proto.ReaderClient) *Client { +func NewClient(client greadcloserproto.ReaderClient) *Client { return &Client{client: client} } // Read ... func (c *Client) Read(p []byte) (int, error) { - resp, err := c.client.Read(context.Background(), &proto.ReadRequest{ + resp, err := c.client.Read(context.Background(), &greadcloserproto.ReadRequest{ Length: int32(len(p)), }) if err != nil { @@ -37,6 +37,6 @@ func (c *Client) Read(p []byte) (int, error) { // Close ... func (c *Client) Close() error { - _, err := c.client.Close(context.Background(), &proto.CloseRequest{}) + _, err := c.client.Close(context.Background(), &greadcloserproto.CloseRequest{}) return err } diff --git a/vms/rpcchainvm/ghttp/greadcloser/reader_server.go b/vms/rpcchainvm/ghttp/greadcloser/reader_server.go index 5dd7602..2cb4d23 100644 --- a/vms/rpcchainvm/ghttp/greadcloser/reader_server.go +++ b/vms/rpcchainvm/ghttp/greadcloser/reader_server.go @@ -7,7 +7,7 @@ import ( "context" "io" - "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greadcloser/proto" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greadcloser/greadcloserproto" ) // Server is a http.Handler that is managed over RPC. @@ -19,10 +19,10 @@ func NewServer(readCloser io.ReadCloser) *Server { } // Read ... -func (s *Server) Read(ctx context.Context, req *proto.ReadRequest) (*proto.ReadResponse, error) { +func (s *Server) Read(ctx context.Context, req *greadcloserproto.ReadRequest) (*greadcloserproto.ReadResponse, error) { buf := make([]byte, int(req.Length)) n, err := s.readCloser.Read(buf) - resp := &proto.ReadResponse{ + resp := &greadcloserproto.ReadResponse{ Read: buf[:n], } if err != nil { @@ -33,6 +33,6 @@ func (s *Server) Read(ctx context.Context, req *proto.ReadRequest) (*proto.ReadR } // Close ... -func (s *Server) Close(ctx context.Context, req *proto.CloseRequest) (*proto.CloseResponse, error) { - return &proto.CloseResponse{}, s.readCloser.Close() +func (s *Server) Close(ctx context.Context, req *greadcloserproto.CloseRequest) (*greadcloserproto.CloseResponse, error) { + return &greadcloserproto.CloseResponse{}, s.readCloser.Close() } diff --git a/vms/rpcchainvm/ghttp/greader/proto/reader.pb.go b/vms/rpcchainvm/ghttp/greader/greaderproto/greader.pb.go similarity index 77% rename from vms/rpcchainvm/ghttp/greader/proto/reader.pb.go rename to vms/rpcchainvm/ghttp/greader/greaderproto/greader.pb.go index 5bdefa0..1781380 100644 --- a/vms/rpcchainvm/ghttp/greader/proto/reader.pb.go +++ b/vms/rpcchainvm/ghttp/greader/greaderproto/greader.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: reader.proto +// source: greader.proto -package proto +package greaderproto import ( context "context" @@ -35,7 +35,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f534e48276761a43, []int{0} + return fileDescriptor_f71c24e059a66efb, []int{0} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -76,7 +76,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f534e48276761a43, []int{1} + return fileDescriptor_f71c24e059a66efb, []int{1} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -119,25 +119,25 @@ func (m *ReadResponse) GetErrored() bool { } func init() { - proto.RegisterType((*ReadRequest)(nil), "proto.ReadRequest") - proto.RegisterType((*ReadResponse)(nil), "proto.ReadResponse") + proto.RegisterType((*ReadRequest)(nil), "greaderproto.ReadRequest") + proto.RegisterType((*ReadResponse)(nil), "greaderproto.ReadResponse") } -func init() { proto.RegisterFile("reader.proto", fileDescriptor_f534e48276761a43) } +func init() { proto.RegisterFile("greader.proto", fileDescriptor_f71c24e059a66efb) } -var fileDescriptor_f534e48276761a43 = []byte{ - // 162 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x8e, 0x41, 0x0a, 0xc2, 0x30, - 0x10, 0x45, 0x89, 0xb6, 0x55, 0xc7, 0xae, 0x46, 0x91, 0xe0, 0xaa, 0x14, 0x84, 0xac, 0x2a, 0xe8, - 0xca, 0x6b, 0xcc, 0x0d, 0x2a, 0x19, 0x74, 0x21, 0x4d, 0x9d, 0xc4, 0xfb, 0x4b, 0x27, 0x0a, 0xba, - 0xca, 0x7f, 0x9f, 0x4f, 0xe6, 0x41, 0x2d, 0xdc, 0x7b, 0x96, 0x6e, 0x94, 0x90, 0x02, 0x96, 0xfa, - 0xb4, 0x07, 0x58, 0x13, 0xf7, 0x9e, 0xf8, 0xf9, 0xe2, 0x98, 0x70, 0x07, 0xd5, 0x83, 0x87, 0x5b, - 0xba, 0x5b, 0xd3, 0x18, 0x57, 0xd2, 0x87, 0x5a, 0x82, 0x3a, 0xcf, 0xe2, 0x18, 0x86, 0xc8, 0x88, - 0x50, 0x4c, 0xbf, 0xe9, 0xaa, 0x26, 0xcd, 0xb8, 0x85, 0x92, 0x45, 0x82, 0xd8, 0x59, 0x63, 0xdc, - 0x8a, 0x32, 0xa0, 0x85, 0x85, 0x06, 0xf6, 0x76, 0xde, 0x18, 0xb7, 0xa4, 0x2f, 0x9e, 0x2e, 0x50, - 0x91, 0x1a, 0xe1, 0x11, 0x8a, 0x29, 0x21, 0x66, 0xb7, 0xee, 0xc7, 0x68, 0xbf, 0xf9, 0xeb, 0xf2, - 0xf9, 0x6b, 0xa5, 0xdd, 0xf9, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x06, 0x11, 0x6f, 0x5d, 0xd3, 0x00, - 0x00, 0x00, +var fileDescriptor_f71c24e059a66efb = []byte{ + // 168 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x8e, 0x31, 0xef, 0x82, 0x30, + 0x10, 0x47, 0xd3, 0xff, 0x1f, 0x50, 0x4f, 0x5c, 0x2e, 0xc6, 0x54, 0x26, 0x42, 0x62, 0xc2, 0xc4, + 0xa0, 0xb3, 0xb3, 0xfb, 0x7d, 0x03, 0x0c, 0x17, 0x1c, 0x0c, 0xc5, 0x6b, 0xfd, 0xfe, 0x86, 0x2b, + 0x26, 0x0c, 0x6e, 0xef, 0xb5, 0xbf, 0x5c, 0x1e, 0xec, 0x7a, 0xe1, 0xb6, 0x63, 0x69, 0x46, 0x71, + 0xc1, 0x61, 0x3e, 0xab, 0x5a, 0x75, 0x82, 0x2d, 0x71, 0xdb, 0x11, 0xbf, 0xde, 0xec, 0x03, 0x1e, + 0x20, 0x7b, 0xf2, 0xd0, 0x87, 0x87, 0x35, 0xa5, 0xa9, 0x53, 0x9a, 0xad, 0x22, 0xc8, 0xe3, 0xcc, + 0x8f, 0x6e, 0xf0, 0x8c, 0x08, 0xc9, 0x74, 0x45, 0x57, 0x39, 0x29, 0xe3, 0x1e, 0x52, 0x16, 0x71, + 0x62, 0xff, 0x4a, 0x53, 0x6f, 0x28, 0x0a, 0x5a, 0x58, 0x29, 0x70, 0x67, 0xff, 0x4b, 0x53, 0xaf, + 0xe9, 0xab, 0xe7, 0x1b, 0x64, 0xa4, 0x25, 0x78, 0x85, 0x64, 0x22, 0x3c, 0x36, 0xcb, 0xb6, 0x66, + 0x11, 0x56, 0x14, 0xbf, 0xbe, 0x62, 0xcc, 0x3d, 0xd3, 0xb7, 0xcb, 0x27, 0x00, 0x00, 0xff, 0xff, + 0xf0, 0x9c, 0xea, 0x36, 0xe9, 0x00, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -165,7 +165,7 @@ func NewReaderClient(cc grpc.ClientConnInterface) ReaderClient { func (c *readerClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) { out := new(ReadResponse) - err := c.cc.Invoke(ctx, "/proto.Reader/Read", in, out, opts...) + err := c.cc.Invoke(ctx, "/greaderproto.Reader/Read", in, out, opts...) if err != nil { return nil, err } @@ -199,7 +199,7 @@ func _Reader_Read_Handler(srv interface{}, ctx context.Context, dec func(interfa } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Reader/Read", + FullMethod: "/greaderproto.Reader/Read", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ReaderServer).Read(ctx, req.(*ReadRequest)) @@ -208,7 +208,7 @@ func _Reader_Read_Handler(srv interface{}, ctx context.Context, dec func(interfa } var _Reader_serviceDesc = grpc.ServiceDesc{ - ServiceName: "proto.Reader", + ServiceName: "greaderproto.Reader", HandlerType: (*ReaderServer)(nil), Methods: []grpc.MethodDesc{ { @@ -217,5 +217,5 @@ var _Reader_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "reader.proto", + Metadata: "greader.proto", } diff --git a/vms/rpcchainvm/ghttp/greader/proto/reader.proto b/vms/rpcchainvm/ghttp/greader/greaderproto/greader.proto similarity index 90% rename from vms/rpcchainvm/ghttp/greader/proto/reader.proto rename to vms/rpcchainvm/ghttp/greader/greaderproto/greader.proto index 80142d3..02994ce 100644 --- a/vms/rpcchainvm/ghttp/greader/proto/reader.proto +++ b/vms/rpcchainvm/ghttp/greader/greaderproto/greader.proto @@ -1,5 +1,5 @@ syntax = "proto3"; -package proto; +package greaderproto; message ReadRequest { int32 length = 1; diff --git a/vms/rpcchainvm/ghttp/greader/reader_client.go b/vms/rpcchainvm/ghttp/greader/reader_client.go index 0505d71..6dd7c5a 100644 --- a/vms/rpcchainvm/ghttp/greader/reader_client.go +++ b/vms/rpcchainvm/ghttp/greader/reader_client.go @@ -7,20 +7,20 @@ import ( "context" "errors" - "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greader/proto" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greader/greaderproto" ) // Client is an implementation of a messenger channel that talks over RPC. -type Client struct{ client proto.ReaderClient } +type Client struct{ client greaderproto.ReaderClient } // NewClient returns a database instance connected to a remote database instance -func NewClient(client proto.ReaderClient) *Client { +func NewClient(client greaderproto.ReaderClient) *Client { return &Client{client: client} } // Read ... func (c *Client) Read(p []byte) (int, error) { - resp, err := c.client.Read(context.Background(), &proto.ReadRequest{ + resp, err := c.client.Read(context.Background(), &greaderproto.ReadRequest{ Length: int32(len(p)), }) if err != nil { diff --git a/vms/rpcchainvm/ghttp/greader/reader_server.go b/vms/rpcchainvm/ghttp/greader/reader_server.go index 840bd66..a86a7a3 100644 --- a/vms/rpcchainvm/ghttp/greader/reader_server.go +++ b/vms/rpcchainvm/ghttp/greader/reader_server.go @@ -7,7 +7,7 @@ import ( "context" "io" - "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greader/proto" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greader/greaderproto" ) // Server is a http.Handler that is managed over RPC. @@ -19,10 +19,10 @@ func NewServer(reader io.Reader) *Server { } // Read ... -func (s *Server) Read(ctx context.Context, req *proto.ReadRequest) (*proto.ReadResponse, error) { +func (s *Server) Read(ctx context.Context, req *greaderproto.ReadRequest) (*greaderproto.ReadResponse, error) { buf := make([]byte, int(req.Length)) n, err := s.reader.Read(buf) - resp := &proto.ReadResponse{ + resp := &greaderproto.ReadResponse{ Read: buf[:n], } if err != nil { diff --git a/vms/rpcchainvm/ghttp/gresponsewriter/proto/writer.pb.go b/vms/rpcchainvm/ghttp/gresponsewriter/gresponsewriterproto/gresponsewriter.pb.go similarity index 80% rename from vms/rpcchainvm/ghttp/gresponsewriter/proto/writer.pb.go rename to vms/rpcchainvm/ghttp/gresponsewriter/gresponsewriterproto/gresponsewriter.pb.go index a392667..4e0d86b 100644 --- a/vms/rpcchainvm/ghttp/gresponsewriter/proto/writer.pb.go +++ b/vms/rpcchainvm/ghttp/gresponsewriter/gresponsewriterproto/gresponsewriter.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: writer.proto +// source: gresponsewriter.proto -package proto +package gresponsewriterproto import ( context "context" @@ -36,7 +36,7 @@ func (m *Header) Reset() { *m = Header{} } func (m *Header) String() string { return proto.CompactTextString(m) } func (*Header) ProtoMessage() {} func (*Header) Descriptor() ([]byte, []int) { - return fileDescriptor_ea6fbe89c42e6759, []int{0} + return fileDescriptor_e66e50a6e6dcfab4, []int{0} } func (m *Header) XXX_Unmarshal(b []byte) error { @@ -83,7 +83,7 @@ func (m *WriteRequest) Reset() { *m = WriteRequest{} } func (m *WriteRequest) String() string { return proto.CompactTextString(m) } func (*WriteRequest) ProtoMessage() {} func (*WriteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_ea6fbe89c42e6759, []int{1} + return fileDescriptor_e66e50a6e6dcfab4, []int{1} } func (m *WriteRequest) XXX_Unmarshal(b []byte) error { @@ -129,7 +129,7 @@ func (m *WriteResponse) Reset() { *m = WriteResponse{} } func (m *WriteResponse) String() string { return proto.CompactTextString(m) } func (*WriteResponse) ProtoMessage() {} func (*WriteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ea6fbe89c42e6759, []int{2} + return fileDescriptor_e66e50a6e6dcfab4, []int{2} } func (m *WriteResponse) XXX_Unmarshal(b []byte) error { @@ -169,7 +169,7 @@ func (m *WriteHeaderRequest) Reset() { *m = WriteHeaderRequest{} } func (m *WriteHeaderRequest) String() string { return proto.CompactTextString(m) } func (*WriteHeaderRequest) ProtoMessage() {} func (*WriteHeaderRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_ea6fbe89c42e6759, []int{3} + return fileDescriptor_e66e50a6e6dcfab4, []int{3} } func (m *WriteHeaderRequest) XXX_Unmarshal(b []byte) error { @@ -214,7 +214,7 @@ func (m *WriteHeaderResponse) Reset() { *m = WriteHeaderResponse{} } func (m *WriteHeaderResponse) String() string { return proto.CompactTextString(m) } func (*WriteHeaderResponse) ProtoMessage() {} func (*WriteHeaderResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ea6fbe89c42e6759, []int{4} + return fileDescriptor_e66e50a6e6dcfab4, []int{4} } func (m *WriteHeaderResponse) XXX_Unmarshal(b []byte) error { @@ -245,7 +245,7 @@ func (m *FlushRequest) Reset() { *m = FlushRequest{} } func (m *FlushRequest) String() string { return proto.CompactTextString(m) } func (*FlushRequest) ProtoMessage() {} func (*FlushRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_ea6fbe89c42e6759, []int{5} + return fileDescriptor_e66e50a6e6dcfab4, []int{5} } func (m *FlushRequest) XXX_Unmarshal(b []byte) error { @@ -276,7 +276,7 @@ func (m *FlushResponse) Reset() { *m = FlushResponse{} } func (m *FlushResponse) String() string { return proto.CompactTextString(m) } func (*FlushResponse) ProtoMessage() {} func (*FlushResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ea6fbe89c42e6759, []int{6} + return fileDescriptor_e66e50a6e6dcfab4, []int{6} } func (m *FlushResponse) XXX_Unmarshal(b []byte) error { @@ -307,7 +307,7 @@ func (m *HijackRequest) Reset() { *m = HijackRequest{} } func (m *HijackRequest) String() string { return proto.CompactTextString(m) } func (*HijackRequest) ProtoMessage() {} func (*HijackRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_ea6fbe89c42e6759, []int{7} + return fileDescriptor_e66e50a6e6dcfab4, []int{7} } func (m *HijackRequest) XXX_Unmarshal(b []byte) error { @@ -345,7 +345,7 @@ func (m *HijackResponse) Reset() { *m = HijackResponse{} } func (m *HijackResponse) String() string { return proto.CompactTextString(m) } func (*HijackResponse) ProtoMessage() {} func (*HijackResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ea6fbe89c42e6759, []int{8} + return fileDescriptor_e66e50a6e6dcfab4, []int{8} } func (m *HijackResponse) XXX_Unmarshal(b []byte) error { @@ -416,47 +416,48 @@ func (m *HijackResponse) GetWriterServer() uint32 { } func init() { - proto.RegisterType((*Header)(nil), "proto.Header") - proto.RegisterType((*WriteRequest)(nil), "proto.WriteRequest") - proto.RegisterType((*WriteResponse)(nil), "proto.WriteResponse") - proto.RegisterType((*WriteHeaderRequest)(nil), "proto.WriteHeaderRequest") - proto.RegisterType((*WriteHeaderResponse)(nil), "proto.WriteHeaderResponse") - proto.RegisterType((*FlushRequest)(nil), "proto.FlushRequest") - proto.RegisterType((*FlushResponse)(nil), "proto.FlushResponse") - proto.RegisterType((*HijackRequest)(nil), "proto.HijackRequest") - proto.RegisterType((*HijackResponse)(nil), "proto.HijackResponse") + proto.RegisterType((*Header)(nil), "gresponsewriterproto.Header") + proto.RegisterType((*WriteRequest)(nil), "gresponsewriterproto.WriteRequest") + proto.RegisterType((*WriteResponse)(nil), "gresponsewriterproto.WriteResponse") + proto.RegisterType((*WriteHeaderRequest)(nil), "gresponsewriterproto.WriteHeaderRequest") + proto.RegisterType((*WriteHeaderResponse)(nil), "gresponsewriterproto.WriteHeaderResponse") + proto.RegisterType((*FlushRequest)(nil), "gresponsewriterproto.FlushRequest") + proto.RegisterType((*FlushResponse)(nil), "gresponsewriterproto.FlushResponse") + proto.RegisterType((*HijackRequest)(nil), "gresponsewriterproto.HijackRequest") + proto.RegisterType((*HijackResponse)(nil), "gresponsewriterproto.HijackResponse") } -func init() { proto.RegisterFile("writer.proto", fileDescriptor_ea6fbe89c42e6759) } +func init() { proto.RegisterFile("gresponsewriter.proto", fileDescriptor_e66e50a6e6dcfab4) } -var fileDescriptor_ea6fbe89c42e6759 = []byte{ - // 408 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0x41, 0x6e, 0xe2, 0x30, - 0x14, 0x86, 0x15, 0x32, 0x09, 0xe2, 0x91, 0xc0, 0xc8, 0x0c, 0xa3, 0x4c, 0x16, 0x28, 0xb2, 0x46, - 0x9a, 0xcc, 0x86, 0x45, 0xaa, 0x9e, 0xa0, 0x55, 0xc5, 0xaa, 0x52, 0xcd, 0xa2, 0xab, 0x2e, 0x52, - 0xb0, 0x0a, 0x25, 0x8d, 0xa9, 0xed, 0x80, 0xb8, 0x41, 0x2f, 0xdb, 0x3b, 0x54, 0xb1, 0x1d, 0x64, - 0x57, 0xdd, 0x74, 0x15, 0xbf, 0xcf, 0x7f, 0xfe, 0xf7, 0xdb, 0xcf, 0x10, 0x1d, 0xf9, 0x56, 0x52, - 0x3e, 0xdf, 0x73, 0x26, 0x19, 0x0a, 0xd4, 0x07, 0x17, 0x10, 0x2e, 0x68, 0xb9, 0xa6, 0x1c, 0xfd, - 0x04, 0x7f, 0x47, 0x4f, 0x89, 0x97, 0x79, 0xf9, 0x80, 0xb4, 0x4b, 0xf4, 0x1b, 0xc2, 0x43, 0x59, - 0x35, 0x54, 0x24, 0xbd, 0xcc, 0xcf, 0x07, 0xc4, 0x54, 0xf8, 0x0e, 0xa2, 0xfb, 0xd6, 0x8a, 0xd0, - 0xd7, 0x86, 0x0a, 0x89, 0xfe, 0x41, 0x7f, 0xa3, 0x3c, 0x44, 0xe2, 0x65, 0x7e, 0x3e, 0x2c, 0x62, - 0xdd, 0x63, 0xae, 0x9d, 0x49, 0xb7, 0x8b, 0x12, 0xe8, 0xef, 0xcb, 0x53, 0xc5, 0xca, 0x75, 0xd2, - 0xcb, 0xbc, 0x3c, 0x22, 0x5d, 0x89, 0xff, 0x43, 0x6c, 0x2c, 0xc5, 0x9e, 0xd5, 0x82, 0xb6, 0xd2, - 0x36, 0xae, 0xa4, 0xb5, 0x4a, 0x14, 0x90, 0xae, 0xc4, 0x0f, 0x80, 0x94, 0xd4, 0x98, 0x7f, 0x37, - 0xc3, 0x0c, 0x40, 0xc8, 0x52, 0x36, 0xe2, 0x8a, 0xad, 0xa9, 0x8a, 0x11, 0x10, 0x8b, 0xe0, 0x29, - 0x4c, 0x1c, 0x7b, 0x9d, 0x07, 0x8f, 0x20, 0xba, 0xa9, 0x1a, 0xb1, 0x31, 0xfd, 0xf0, 0x18, 0x62, - 0x53, 0x1b, 0xc1, 0x18, 0xe2, 0xc5, 0xf6, 0xb9, 0x5c, 0xed, 0x3a, 0xc5, 0x5b, 0x0f, 0x46, 0x1d, - 0x31, 0x87, 0x9a, 0x01, 0xac, 0x58, 0x5d, 0x2f, 0x29, 0x3f, 0x50, 0xae, 0xce, 0x15, 0x13, 0x8b, - 0x20, 0x0c, 0x51, 0xc5, 0x56, 0x65, 0x75, 0x4b, 0xe5, 0x91, 0xf1, 0x9d, 0x4a, 0x37, 0x20, 0x0e, - 0x43, 0x19, 0x0c, 0x55, 0xbd, 0x94, 0x7c, 0x5b, 0x3f, 0x25, 0xbe, 0x92, 0xd8, 0x08, 0xfd, 0x85, - 0x98, 0xd3, 0x17, 0x26, 0x69, 0x67, 0xf3, 0x43, 0x69, 0x5c, 0xd8, 0xf6, 0xd2, 0xc0, 0x18, 0x05, - 0xba, 0x97, 0xcd, 0xb4, 0xa6, 0xbd, 0x06, 0x93, 0x38, 0x54, 0x89, 0x1d, 0xd6, 0x6a, 0xf4, 0xbb, - 0x32, 0x9a, 0xbe, 0xd6, 0xd8, 0xac, 0x78, 0xf7, 0x20, 0x54, 0x97, 0xca, 0x51, 0x01, 0x81, 0x5a, - 0xa1, 0x89, 0x99, 0x8f, 0xfd, 0x92, 0xd2, 0x5f, 0x2e, 0x34, 0xd7, 0x76, 0x0d, 0x43, 0x6b, 0x24, - 0xe8, 0x8f, 0x2d, 0x72, 0x5e, 0x41, 0x9a, 0x7e, 0xb5, 0x65, 0x5c, 0x0a, 0x08, 0xd4, 0xc4, 0xce, - 0x9d, 0xed, 0x79, 0x9e, 0x3b, 0x3b, 0x43, 0x45, 0x97, 0x10, 0xea, 0x11, 0xa2, 0x6e, 0xdf, 0x99, - 0x71, 0x3a, 0xfd, 0x44, 0xf5, 0x6f, 0x8f, 0xa1, 0xa2, 0x17, 0x1f, 0x01, 0x00, 0x00, 0xff, 0xff, - 0x6f, 0xbe, 0x4a, 0x4f, 0x72, 0x03, 0x00, 0x00, +var fileDescriptor_e66e50a6e6dcfab4 = []byte{ + // 426 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0xc1, 0xaa, 0xda, 0x40, + 0x14, 0x86, 0x49, 0xd2, 0x44, 0x3c, 0x26, 0xf7, 0x96, 0x69, 0xef, 0x25, 0x48, 0x91, 0x30, 0x75, + 0x11, 0x37, 0x2e, 0x2c, 0xf4, 0x01, 0x5a, 0x28, 0xae, 0x8a, 0x8c, 0x8b, 0x42, 0x57, 0x8d, 0x7a, + 0x50, 0x6b, 0x9a, 0xb1, 0x33, 0x13, 0xc5, 0x37, 0xe8, 0x8b, 0xf6, 0x3d, 0x4a, 0x66, 0x26, 0x30, + 0x29, 0x2a, 0x85, 0xae, 0xcc, 0xf9, 0xfd, 0xfc, 0xff, 0x3f, 0x33, 0x07, 0xe1, 0x69, 0x2b, 0x50, + 0x1e, 0x79, 0x25, 0xf1, 0x2c, 0xf6, 0x0a, 0xc5, 0xf4, 0x28, 0xb8, 0xe2, 0xe4, 0xf5, 0x5f, 0xb2, + 0x56, 0xe9, 0x0c, 0xa2, 0x39, 0x16, 0x1b, 0x14, 0xe4, 0x25, 0x04, 0x07, 0xbc, 0xa4, 0x5e, 0xe6, + 0xe5, 0x7d, 0xd6, 0x3c, 0x92, 0x67, 0x88, 0x4e, 0x45, 0x59, 0xa3, 0x4c, 0xfd, 0x2c, 0xc8, 0xfb, + 0xcc, 0x4e, 0xf4, 0x1b, 0xc4, 0x5f, 0x1a, 0x0b, 0x86, 0x3f, 0x6b, 0x94, 0x8a, 0xbc, 0x87, 0xde, + 0x4e, 0x7b, 0xc8, 0xd4, 0xcb, 0x82, 0x7c, 0x30, 0x7b, 0x33, 0xbd, 0x96, 0x35, 0x35, 0x41, 0xac, + 0x85, 0x49, 0x0a, 0xbd, 0x63, 0x71, 0x29, 0x79, 0xb1, 0x49, 0xfd, 0xcc, 0xcb, 0x63, 0xd6, 0x8e, + 0x74, 0x02, 0x89, 0x4d, 0x30, 0x2e, 0x0d, 0xda, 0x38, 0x29, 0xac, 0x74, 0xc1, 0x90, 0xb5, 0x23, + 0x2d, 0x81, 0x68, 0xd4, 0x9a, 0xff, 0x67, 0xa5, 0x11, 0x80, 0x54, 0x85, 0xaa, 0xe5, 0x47, 0xbe, + 0x41, 0xdd, 0x2a, 0x64, 0x8e, 0x42, 0x9f, 0xe0, 0x55, 0x27, 0xcd, 0x38, 0xd2, 0x07, 0x88, 0x3f, + 0x95, 0xb5, 0xdc, 0xd9, 0x78, 0xfa, 0x08, 0x89, 0x9d, 0x2d, 0xf0, 0x08, 0xc9, 0x7c, 0xff, 0xbd, + 0x58, 0x1f, 0x5a, 0xe2, 0x97, 0x0f, 0x0f, 0xad, 0x62, 0xdf, 0x71, 0x04, 0xb0, 0xe6, 0x55, 0xb5, + 0x44, 0x71, 0x42, 0xa1, 0x5f, 0x33, 0x61, 0x8e, 0x42, 0x28, 0xc4, 0x25, 0x5f, 0x17, 0xe5, 0x67, + 0x54, 0x67, 0x2e, 0x0e, 0xba, 0x5d, 0x9f, 0x75, 0x34, 0x92, 0xc1, 0x40, 0xcf, 0x4b, 0x25, 0xf6, + 0xd5, 0x36, 0x0d, 0x34, 0xe2, 0x4a, 0x64, 0x0c, 0x89, 0xc0, 0x1f, 0x5c, 0x61, 0x6b, 0xf3, 0x42, + 0x33, 0x5d, 0xb1, 0xc9, 0x32, 0x82, 0x35, 0x0a, 0x4d, 0x96, 0xab, 0x19, 0xa6, 0x39, 0x06, 0xdb, + 0x38, 0xd2, 0x8d, 0x3b, 0x5a, 0xc3, 0x98, 0xe3, 0xb6, 0x4c, 0xcf, 0x30, 0xae, 0x36, 0xfb, 0xed, + 0x43, 0xa4, 0x0f, 0x55, 0x90, 0x05, 0x84, 0xfa, 0x89, 0xd0, 0xeb, 0xd7, 0xe5, 0xae, 0xdd, 0xf0, + 0xed, 0x5d, 0xc6, 0x1e, 0xea, 0x0a, 0x06, 0xce, 0x85, 0x91, 0xfc, 0xce, 0x6f, 0x3a, 0x1b, 0x34, + 0x9c, 0xfc, 0x03, 0x69, 0x33, 0x16, 0x10, 0xea, 0xdb, 0xbe, 0xd5, 0xda, 0x5d, 0x8d, 0x5b, 0xad, + 0x3b, 0xeb, 0x42, 0x96, 0x10, 0x99, 0xe5, 0x20, 0x37, 0xf0, 0xce, 0x32, 0x0d, 0xc7, 0xf7, 0x21, + 0xf3, 0xcd, 0x87, 0xe7, 0xaf, 0x57, 0xff, 0x02, 0x56, 0x91, 0xfe, 0x78, 0xf7, 0x27, 0x00, 0x00, + 0xff, 0xff, 0x9f, 0x44, 0xb9, 0xc8, 0x38, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -487,7 +488,7 @@ func NewWriterClient(cc grpc.ClientConnInterface) WriterClient { func (c *writerClient) Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) { out := new(WriteResponse) - err := c.cc.Invoke(ctx, "/proto.Writer/Write", in, out, opts...) + err := c.cc.Invoke(ctx, "/gresponsewriterproto.Writer/Write", in, out, opts...) if err != nil { return nil, err } @@ -496,7 +497,7 @@ func (c *writerClient) Write(ctx context.Context, in *WriteRequest, opts ...grpc func (c *writerClient) WriteHeader(ctx context.Context, in *WriteHeaderRequest, opts ...grpc.CallOption) (*WriteHeaderResponse, error) { out := new(WriteHeaderResponse) - err := c.cc.Invoke(ctx, "/proto.Writer/WriteHeader", in, out, opts...) + err := c.cc.Invoke(ctx, "/gresponsewriterproto.Writer/WriteHeader", in, out, opts...) if err != nil { return nil, err } @@ -505,7 +506,7 @@ func (c *writerClient) WriteHeader(ctx context.Context, in *WriteHeaderRequest, func (c *writerClient) Flush(ctx context.Context, in *FlushRequest, opts ...grpc.CallOption) (*FlushResponse, error) { out := new(FlushResponse) - err := c.cc.Invoke(ctx, "/proto.Writer/Flush", in, out, opts...) + err := c.cc.Invoke(ctx, "/gresponsewriterproto.Writer/Flush", in, out, opts...) if err != nil { return nil, err } @@ -514,7 +515,7 @@ func (c *writerClient) Flush(ctx context.Context, in *FlushRequest, opts ...grpc func (c *writerClient) Hijack(ctx context.Context, in *HijackRequest, opts ...grpc.CallOption) (*HijackResponse, error) { out := new(HijackResponse) - err := c.cc.Invoke(ctx, "/proto.Writer/Hijack", in, out, opts...) + err := c.cc.Invoke(ctx, "/gresponsewriterproto.Writer/Hijack", in, out, opts...) if err != nil { return nil, err } @@ -560,7 +561,7 @@ func _Writer_Write_Handler(srv interface{}, ctx context.Context, dec func(interf } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Writer/Write", + FullMethod: "/gresponsewriterproto.Writer/Write", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(WriterServer).Write(ctx, req.(*WriteRequest)) @@ -578,7 +579,7 @@ func _Writer_WriteHeader_Handler(srv interface{}, ctx context.Context, dec func( } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Writer/WriteHeader", + FullMethod: "/gresponsewriterproto.Writer/WriteHeader", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(WriterServer).WriteHeader(ctx, req.(*WriteHeaderRequest)) @@ -596,7 +597,7 @@ func _Writer_Flush_Handler(srv interface{}, ctx context.Context, dec func(interf } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Writer/Flush", + FullMethod: "/gresponsewriterproto.Writer/Flush", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(WriterServer).Flush(ctx, req.(*FlushRequest)) @@ -614,7 +615,7 @@ func _Writer_Hijack_Handler(srv interface{}, ctx context.Context, dec func(inter } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Writer/Hijack", + FullMethod: "/gresponsewriterproto.Writer/Hijack", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(WriterServer).Hijack(ctx, req.(*HijackRequest)) @@ -623,7 +624,7 @@ func _Writer_Hijack_Handler(srv interface{}, ctx context.Context, dec func(inter } var _Writer_serviceDesc = grpc.ServiceDesc{ - ServiceName: "proto.Writer", + ServiceName: "gresponsewriterproto.Writer", HandlerType: (*WriterServer)(nil), Methods: []grpc.MethodDesc{ { @@ -644,5 +645,5 @@ var _Writer_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "writer.proto", + Metadata: "gresponsewriter.proto", } diff --git a/vms/rpcchainvm/ghttp/gresponsewriter/proto/writer.proto b/vms/rpcchainvm/ghttp/gresponsewriter/gresponsewriterproto/gresponsewriter.proto similarity index 92% rename from vms/rpcchainvm/ghttp/gresponsewriter/proto/writer.proto rename to vms/rpcchainvm/ghttp/gresponsewriter/gresponsewriterproto/gresponsewriter.proto index 121c661..c0a9aa5 100644 --- a/vms/rpcchainvm/ghttp/gresponsewriter/proto/writer.proto +++ b/vms/rpcchainvm/ghttp/gresponsewriter/gresponsewriterproto/gresponsewriter.proto @@ -1,5 +1,6 @@ syntax = "proto3"; -package proto; +package gresponsewriterproto; +option go_package = "gresponsewriterproto"; message Header { string key = 1; diff --git a/vms/rpcchainvm/ghttp/gresponsewriter/writer_client.go b/vms/rpcchainvm/ghttp/gresponsewriter/writer_client.go index bcd880b..e78f0cd 100644 --- a/vms/rpcchainvm/ghttp/gresponsewriter/writer_client.go +++ b/vms/rpcchainvm/ghttp/gresponsewriter/writer_client.go @@ -12,24 +12,23 @@ import ( "github.com/hashicorp/go-plugin" "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gconn" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gconn/gconnproto" "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greader" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greader/greaderproto" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gresponsewriter/gresponsewriterproto" "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gwriter" - - connproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gconn/proto" - readerproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greader/proto" - responsewriterproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gresponsewriter/proto" - writerproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gwriter/proto" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gwriter/gwriterproto" ) // Client is an implementation of a messenger channel that talks over RPC. type Client struct { - client responsewriterproto.WriterClient + client gresponsewriterproto.WriterClient header http.Header broker *plugin.GRPCBroker } // NewClient returns a database instance connected to a remote database instance -func NewClient(client responsewriterproto.WriterClient, broker *plugin.GRPCBroker) *Client { +func NewClient(client gresponsewriterproto.WriterClient, broker *plugin.GRPCBroker) *Client { return &Client{ client: client, header: make(http.Header), @@ -42,12 +41,12 @@ func (c *Client) Header() http.Header { return c.header } // Write ... func (c *Client) Write(payload []byte) (int, error) { - req := &responsewriterproto.WriteRequest{ - Headers: make([]*responsewriterproto.Header, 0, len(c.header)), + req := &gresponsewriterproto.WriteRequest{ + Headers: make([]*gresponsewriterproto.Header, 0, len(c.header)), Payload: payload, } for key, values := range c.header { - req.Headers = append(req.Headers, &responsewriterproto.Header{ + req.Headers = append(req.Headers, &gresponsewriterproto.Header{ Key: key, Values: values, }) @@ -61,12 +60,12 @@ func (c *Client) Write(payload []byte) (int, error) { // WriteHeader ... func (c *Client) WriteHeader(statusCode int) { - req := &responsewriterproto.WriteHeaderRequest{ - Headers: make([]*responsewriterproto.Header, 0, len(c.header)), + req := &gresponsewriterproto.WriteHeaderRequest{ + Headers: make([]*gresponsewriterproto.Header, 0, len(c.header)), StatusCode: int32(statusCode), } for key, values := range c.header { - req.Headers = append(req.Headers, &responsewriterproto.Header{ + req.Headers = append(req.Headers, &gresponsewriterproto.Header{ Key: key, Values: values, }) @@ -78,7 +77,7 @@ func (c *Client) WriteHeader(statusCode int) { // Flush ... func (c *Client) Flush() { // TODO: How should we handle an error here? - c.client.Flush(context.Background(), &responsewriterproto.FlushRequest{}) + c.client.Flush(context.Background(), &gresponsewriterproto.FlushRequest{}) } type addr struct { @@ -91,7 +90,7 @@ func (a *addr) String() string { return a.str } // Hijack ... func (c *Client) Hijack() (net.Conn, *bufio.ReadWriter, error) { - resp, err := c.client.Hijack(context.Background(), &responsewriterproto.HijackRequest{}) + resp, err := c.client.Hijack(context.Background(), &gresponsewriterproto.HijackRequest{}) if err != nil { return nil, nil, err } @@ -114,7 +113,7 @@ func (c *Client) Hijack() (net.Conn, *bufio.ReadWriter, error) { return nil, nil, err } - conn := gconn.NewClient(connproto.NewConnClient(connConn), &addr{ + conn := gconn.NewClient(gconnproto.NewConnClient(connConn), &addr{ network: resp.LocalNetwork, str: resp.LocalString, }, &addr{ @@ -122,8 +121,8 @@ func (c *Client) Hijack() (net.Conn, *bufio.ReadWriter, error) { str: resp.RemoteString, }, connConn, readerConn, writerConn) - reader := greader.NewClient(readerproto.NewReaderClient(readerConn)) - writer := gwriter.NewClient(writerproto.NewWriterClient(writerConn)) + reader := greader.NewClient(greaderproto.NewReaderClient(readerConn)) + writer := gwriter.NewClient(gwriterproto.NewWriterClient(writerConn)) readWriter := bufio.NewReadWriter( bufio.NewReader(reader), diff --git a/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go b/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go index 296fad2..71e1ba3 100644 --- a/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go +++ b/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go @@ -8,17 +8,17 @@ import ( "errors" "net/http" - "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gconn" - "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greader" - "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gwriter" - - "github.com/hashicorp/go-plugin" "google.golang.org/grpc" - connproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gconn/proto" - readerproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greader/proto" - responsewriterproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gresponsewriter/proto" - writerproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gwriter/proto" + "github.com/hashicorp/go-plugin" + + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gconn" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gconn/gconnproto" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greader" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greader/greaderproto" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gresponsewriter/gresponsewriterproto" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gwriter" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gwriter/gwriterproto" ) // Server is a http.Handler that is managed over RPC. @@ -36,7 +36,7 @@ func NewServer(writer http.ResponseWriter, broker *plugin.GRPCBroker) *Server { } // Write ... -func (s *Server) Write(ctx context.Context, req *responsewriterproto.WriteRequest) (*responsewriterproto.WriteResponse, error) { +func (s *Server) Write(ctx context.Context, req *gresponsewriterproto.WriteRequest) (*gresponsewriterproto.WriteResponse, error) { headers := s.writer.Header() for key := range headers { delete(headers, key) @@ -49,13 +49,13 @@ func (s *Server) Write(ctx context.Context, req *responsewriterproto.WriteReques if err != nil { return nil, err } - return &responsewriterproto.WriteResponse{ + return &gresponsewriterproto.WriteResponse{ Written: int32(n), }, nil } // WriteHeader ... -func (s *Server) WriteHeader(ctx context.Context, req *responsewriterproto.WriteHeaderRequest) (*responsewriterproto.WriteHeaderResponse, error) { +func (s *Server) WriteHeader(ctx context.Context, req *gresponsewriterproto.WriteHeaderRequest) (*gresponsewriterproto.WriteHeaderResponse, error) { headers := s.writer.Header() for key := range headers { delete(headers, key) @@ -64,21 +64,21 @@ func (s *Server) WriteHeader(ctx context.Context, req *responsewriterproto.Write headers[header.Key] = header.Values } s.writer.WriteHeader(int(req.StatusCode)) - return &responsewriterproto.WriteHeaderResponse{}, nil + return &gresponsewriterproto.WriteHeaderResponse{}, nil } // Flush ... -func (s *Server) Flush(ctx context.Context, req *responsewriterproto.FlushRequest) (*responsewriterproto.FlushResponse, error) { +func (s *Server) Flush(ctx context.Context, req *gresponsewriterproto.FlushRequest) (*gresponsewriterproto.FlushResponse, error) { flusher, ok := s.writer.(http.Flusher) if !ok { return nil, errors.New("response writer doesn't support flushing") } flusher.Flush() - return &responsewriterproto.FlushResponse{}, nil + return &gresponsewriterproto.FlushResponse{}, nil } // Hijack ... -func (s *Server) Hijack(ctx context.Context, req *responsewriterproto.HijackRequest) (*responsewriterproto.HijackResponse, error) { +func (s *Server) Hijack(ctx context.Context, req *gresponsewriterproto.HijackRequest) (*gresponsewriterproto.HijackResponse, error) { hijacker, ok := s.writer.(http.Hijacker) if !ok { return nil, errors.New("response writer doesn't support hijacking") @@ -94,24 +94,24 @@ func (s *Server) Hijack(ctx context.Context, req *responsewriterproto.HijackRequ go s.broker.AcceptAndServe(connID, func(opts []grpc.ServerOption) *grpc.Server { connServer := grpc.NewServer(opts...) - connproto.RegisterConnServer(connServer, gconn.NewServer(conn)) + gconnproto.RegisterConnServer(connServer, gconn.NewServer(conn)) return connServer }) go s.broker.AcceptAndServe(readerID, func(opts []grpc.ServerOption) *grpc.Server { readerServer := grpc.NewServer(opts...) - readerproto.RegisterReaderServer(readerServer, greader.NewServer(readWriter)) + greaderproto.RegisterReaderServer(readerServer, greader.NewServer(readWriter)) return readerServer }) go s.broker.AcceptAndServe(writerID, func(opts []grpc.ServerOption) *grpc.Server { writerServer := grpc.NewServer(opts...) - writerproto.RegisterWriterServer(writerServer, gwriter.NewServer(readWriter)) + gwriterproto.RegisterWriterServer(writerServer, gwriter.NewServer(readWriter)) return writerServer }) local := conn.LocalAddr() remote := conn.RemoteAddr() - return &responsewriterproto.HijackResponse{ + return &gresponsewriterproto.HijackResponse{ ConnServer: connID, LocalNetwork: local.Network(), LocalString: local.String(), diff --git a/vms/rpcchainvm/ghttp/gwriter/proto/writer.pb.go b/vms/rpcchainvm/ghttp/gwriter/gwriterproto/gwriter.pb.go similarity index 78% rename from vms/rpcchainvm/ghttp/gwriter/proto/writer.pb.go rename to vms/rpcchainvm/ghttp/gwriter/gwriterproto/gwriter.pb.go index fe0e7bf..a81a756 100644 --- a/vms/rpcchainvm/ghttp/gwriter/proto/writer.pb.go +++ b/vms/rpcchainvm/ghttp/gwriter/gwriterproto/gwriter.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: writer.proto +// source: gwriter.proto -package proto +package gwriterproto import ( context "context" @@ -35,7 +35,7 @@ func (m *WriteRequest) Reset() { *m = WriteRequest{} } func (m *WriteRequest) String() string { return proto.CompactTextString(m) } func (*WriteRequest) ProtoMessage() {} func (*WriteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_ea6fbe89c42e6759, []int{0} + return fileDescriptor_0043bbf29025db7a, []int{0} } func (m *WriteRequest) XXX_Unmarshal(b []byte) error { @@ -76,7 +76,7 @@ func (m *WriteResponse) Reset() { *m = WriteResponse{} } func (m *WriteResponse) String() string { return proto.CompactTextString(m) } func (*WriteResponse) ProtoMessage() {} func (*WriteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ea6fbe89c42e6759, []int{1} + return fileDescriptor_0043bbf29025db7a, []int{1} } func (m *WriteResponse) XXX_Unmarshal(b []byte) error { @@ -119,25 +119,25 @@ func (m *WriteResponse) GetErrored() bool { } func init() { - proto.RegisterType((*WriteRequest)(nil), "proto.WriteRequest") - proto.RegisterType((*WriteResponse)(nil), "proto.WriteResponse") + proto.RegisterType((*WriteRequest)(nil), "gwriterproto.WriteRequest") + proto.RegisterType((*WriteResponse)(nil), "gwriterproto.WriteResponse") } -func init() { proto.RegisterFile("writer.proto", fileDescriptor_ea6fbe89c42e6759) } +func init() { proto.RegisterFile("gwriter.proto", fileDescriptor_0043bbf29025db7a) } -var fileDescriptor_ea6fbe89c42e6759 = []byte{ - // 164 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0x2f, 0xca, 0x2c, - 0x49, 0x2d, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, 0x4a, 0x1a, 0x5c, 0x3c, - 0xe1, 0x20, 0xe1, 0xa0, 0xd4, 0xc2, 0xd2, 0xd4, 0xe2, 0x12, 0x21, 0x09, 0x2e, 0xf6, 0x82, 0xc4, - 0xca, 0x9c, 0xfc, 0xc4, 0x14, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x9e, 0x20, 0x18, 0x57, 0x29, 0x92, - 0x8b, 0x17, 0xaa, 0xb2, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x15, 0xa4, 0x14, 0x64, 0x62, 0x49, 0x6a, - 0x1e, 0x58, 0x29, 0x6b, 0x10, 0x8c, 0x2b, 0x24, 0xc2, 0xc5, 0x9a, 0x5a, 0x54, 0x94, 0x5f, 0x24, - 0xc1, 0xa4, 0xc0, 0xa8, 0xc1, 0x19, 0x04, 0xe1, 0x80, 0xd4, 0x83, 0x19, 0xa9, 0x29, 0x12, 0xcc, - 0x0a, 0x8c, 0x1a, 0x1c, 0x41, 0x30, 0xae, 0x91, 0x0d, 0x17, 0x1b, 0xd8, 0xe8, 0x22, 0x21, 0x23, - 0x2e, 0x56, 0x30, 0x4b, 0x48, 0x18, 0xe2, 0x4c, 0x3d, 0x64, 0xc7, 0x49, 0x89, 0xa0, 0x0a, 0x42, - 0xdc, 0x91, 0xc4, 0x06, 0x16, 0x34, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x3e, 0x3f, 0xbb, 0x2f, - 0xe0, 0x00, 0x00, 0x00, +var fileDescriptor_0043bbf29025db7a = []byte{ + // 168 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4d, 0x2f, 0x2f, 0xca, + 0x2c, 0x49, 0x2d, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x81, 0x72, 0xc1, 0x3c, 0x25, + 0x0d, 0x2e, 0x9e, 0x70, 0x10, 0x37, 0x28, 0xb5, 0xb0, 0x34, 0xb5, 0xb8, 0x44, 0x48, 0x82, 0x8b, + 0xbd, 0x20, 0xb1, 0x32, 0x27, 0x3f, 0x31, 0x45, 0x82, 0x51, 0x81, 0x51, 0x83, 0x27, 0x08, 0xc6, + 0x55, 0x8a, 0xe4, 0xe2, 0x85, 0xaa, 0x2c, 0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0x05, 0x29, 0x05, 0x99, + 0x54, 0x92, 0x9a, 0x07, 0x56, 0xca, 0x1a, 0x04, 0xe3, 0x0a, 0x89, 0x70, 0xb1, 0xa6, 0x16, 0x15, + 0xe5, 0x17, 0x49, 0x30, 0x29, 0x30, 0x6a, 0x70, 0x06, 0x41, 0x38, 0x20, 0xf5, 0x60, 0x46, 0x6a, + 0x8a, 0x04, 0xb3, 0x02, 0xa3, 0x06, 0x47, 0x10, 0x8c, 0x6b, 0xe4, 0xc5, 0xc5, 0x06, 0x36, 0xba, + 0x48, 0xc8, 0x81, 0x8b, 0x15, 0xcc, 0x12, 0x92, 0xd2, 0x43, 0x76, 0xa6, 0x1e, 0xb2, 0x1b, 0xa5, + 0xa4, 0xb1, 0xca, 0x41, 0x5c, 0x95, 0xc4, 0x06, 0x16, 0x34, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, + 0xb2, 0xf2, 0x80, 0x6f, 0xf6, 0x00, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -165,7 +165,7 @@ func NewWriterClient(cc grpc.ClientConnInterface) WriterClient { func (c *writerClient) Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) { out := new(WriteResponse) - err := c.cc.Invoke(ctx, "/proto.Writer/Write", in, out, opts...) + err := c.cc.Invoke(ctx, "/gwriterproto.Writer/Write", in, out, opts...) if err != nil { return nil, err } @@ -199,7 +199,7 @@ func _Writer_Write_Handler(srv interface{}, ctx context.Context, dec func(interf } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Writer/Write", + FullMethod: "/gwriterproto.Writer/Write", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(WriterServer).Write(ctx, req.(*WriteRequest)) @@ -208,7 +208,7 @@ func _Writer_Write_Handler(srv interface{}, ctx context.Context, dec func(interf } var _Writer_serviceDesc = grpc.ServiceDesc{ - ServiceName: "proto.Writer", + ServiceName: "gwriterproto.Writer", HandlerType: (*WriterServer)(nil), Methods: []grpc.MethodDesc{ { @@ -217,5 +217,5 @@ var _Writer_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "writer.proto", + Metadata: "gwriter.proto", } diff --git a/vms/rpcchainvm/ghttp/gwriter/proto/writer.proto b/vms/rpcchainvm/ghttp/gwriter/gwriterproto/gwriter.proto similarity index 91% rename from vms/rpcchainvm/ghttp/gwriter/proto/writer.proto rename to vms/rpcchainvm/ghttp/gwriter/gwriterproto/gwriter.proto index 0baa7d6..3618247 100644 --- a/vms/rpcchainvm/ghttp/gwriter/proto/writer.proto +++ b/vms/rpcchainvm/ghttp/gwriter/gwriterproto/gwriter.proto @@ -1,5 +1,5 @@ syntax = "proto3"; -package proto; +package gwriterproto; message WriteRequest { bytes payload = 1; diff --git a/vms/rpcchainvm/ghttp/gwriter/writer_client.go b/vms/rpcchainvm/ghttp/gwriter/writer_client.go index f229a3d..7cf8786 100644 --- a/vms/rpcchainvm/ghttp/gwriter/writer_client.go +++ b/vms/rpcchainvm/ghttp/gwriter/writer_client.go @@ -7,20 +7,20 @@ import ( "context" "errors" - "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gwriter/proto" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gwriter/gwriterproto" ) // Client is an implementation of a messenger channel that talks over RPC. -type Client struct{ client proto.WriterClient } +type Client struct{ client gwriterproto.WriterClient } // NewClient returns a database instance connected to a remote database instance -func NewClient(client proto.WriterClient) *Client { +func NewClient(client gwriterproto.WriterClient) *Client { return &Client{client: client} } // Write ... func (c *Client) Write(p []byte) (int, error) { - resp, err := c.client.Write(context.Background(), &proto.WriteRequest{ + resp, err := c.client.Write(context.Background(), &gwriterproto.WriteRequest{ Payload: p, }) if err != nil { diff --git a/vms/rpcchainvm/ghttp/gwriter/writer_server.go b/vms/rpcchainvm/ghttp/gwriter/writer_server.go index 5d1d800..e33712c 100644 --- a/vms/rpcchainvm/ghttp/gwriter/writer_server.go +++ b/vms/rpcchainvm/ghttp/gwriter/writer_server.go @@ -7,7 +7,7 @@ import ( "context" "io" - "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gwriter/proto" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gwriter/gwriterproto" ) // Server is a http.Handler that is managed over RPC. @@ -19,9 +19,9 @@ func NewServer(writer io.Writer) *Server { } // Write ... -func (s *Server) Write(ctx context.Context, req *proto.WriteRequest) (*proto.WriteResponse, error) { +func (s *Server) Write(ctx context.Context, req *gwriterproto.WriteRequest) (*gwriterproto.WriteResponse, error) { n, err := s.writer.Write(req.Payload) - resp := &proto.WriteResponse{ + resp := &gwriterproto.WriteResponse{ Written: int32(n), } if err != nil { diff --git a/vms/rpcchainvm/ghttp/http_client.go b/vms/rpcchainvm/ghttp/http_client.go index edb8347..10b5f6c 100644 --- a/vms/rpcchainvm/ghttp/http_client.go +++ b/vms/rpcchainvm/ghttp/http_client.go @@ -10,22 +10,21 @@ import ( "github.com/hashicorp/go-plugin" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/ghttpproto" "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greadcloser" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greadcloser/greadcloserproto" "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gresponsewriter" - - readcloserproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greadcloser/proto" - responsewriterproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gresponsewriter/proto" - httpproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/proto" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gresponsewriter/gresponsewriterproto" ) // Client is an implementation of a messenger channel that talks over RPC. type Client struct { - client httpproto.HTTPClient + client ghttpproto.HTTPClient broker *plugin.GRPCBroker } // NewClient returns a database instance connected to a remote database instance -func NewClient(client httpproto.HTTPClient, broker *plugin.GRPCBroker) *Client { +func NewClient(client ghttpproto.HTTPClient, broker *plugin.GRPCBroker) *Client { return &Client{ client: client, broker: broker, @@ -40,21 +39,21 @@ func (c *Client) ServeHTTP(w http.ResponseWriter, r *http.Request) { readerID := c.broker.NextId() go c.broker.AcceptAndServe(readerID, func(opts []grpc.ServerOption) *grpc.Server { reader = grpc.NewServer(opts...) - readcloserproto.RegisterReaderServer(reader, greadcloser.NewServer(r.Body)) + greadcloserproto.RegisterReaderServer(reader, greadcloser.NewServer(r.Body)) return reader }) writerID := c.broker.NextId() go c.broker.AcceptAndServe(writerID, func(opts []grpc.ServerOption) *grpc.Server { writer = grpc.NewServer(opts...) - responsewriterproto.RegisterWriterServer(writer, gresponsewriter.NewServer(w, c.broker)) + gresponsewriterproto.RegisterWriterServer(writer, gresponsewriter.NewServer(w, c.broker)) return writer }) - req := &httpproto.HTTPRequest{ + req := &ghttpproto.HTTPRequest{ ResponseWriter: writerID, - Request: &httpproto.Request{ + Request: &ghttpproto.Request{ Method: r.Method, Proto: r.Proto, ProtoMajor: int32(r.ProtoMajor), @@ -67,32 +66,32 @@ func (c *Client) ServeHTTP(w http.ResponseWriter, r *http.Request) { RequestURI: r.RequestURI, }, } - req.Request.Header = make([]*httpproto.Element, 0, len(r.Header)) + req.Request.Header = make([]*ghttpproto.Element, 0, len(r.Header)) for key, values := range r.Header { - req.Request.Header = append(req.Request.Header, &httpproto.Element{ + req.Request.Header = append(req.Request.Header, &ghttpproto.Element{ Key: key, Values: values, }) } - req.Request.Form = make([]*httpproto.Element, 0, len(r.Form)) + req.Request.Form = make([]*ghttpproto.Element, 0, len(r.Form)) for key, values := range r.Form { - req.Request.Form = append(req.Request.Form, &httpproto.Element{ + req.Request.Form = append(req.Request.Form, &ghttpproto.Element{ Key: key, Values: values, }) } - req.Request.PostForm = make([]*httpproto.Element, 0, len(r.PostForm)) + req.Request.PostForm = make([]*ghttpproto.Element, 0, len(r.PostForm)) for key, values := range r.PostForm { - req.Request.PostForm = append(req.Request.PostForm, &httpproto.Element{ + req.Request.PostForm = append(req.Request.PostForm, &ghttpproto.Element{ Key: key, Values: values, }) } if r.URL != nil { - req.Request.Url = &httpproto.URL{ + req.Request.Url = &ghttpproto.URL{ Scheme: r.URL.Scheme, Opaque: r.URL.Opaque, Host: r.URL.Host, @@ -104,7 +103,7 @@ func (c *Client) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if r.URL.User != nil { - req.Request.Url.User = &httpproto.Userinfo{ + req.Request.Url.User = &ghttpproto.Userinfo{ Username: r.URL.User.Username(), } pwd, set := r.URL.User.Password() @@ -114,7 +113,7 @@ func (c *Client) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if r.TLS != nil { - req.Request.Tls = &httpproto.ConnectionState{ + req.Request.Tls = &ghttpproto.ConnectionState{ Version: uint32(r.TLS.Version), HandshakeComplete: r.TLS.HandshakeComplete, DidResume: r.TLS.DidResume, @@ -127,16 +126,16 @@ func (c *Client) ServeHTTP(w http.ResponseWriter, r *http.Request) { TlsUnique: r.TLS.TLSUnique, } - req.Request.Tls.PeerCertificates = &httpproto.Certificates{ + req.Request.Tls.PeerCertificates = &ghttpproto.Certificates{ Cert: make([][]byte, len(r.TLS.PeerCertificates)), } for i, cert := range r.TLS.PeerCertificates { req.Request.Tls.PeerCertificates.Cert[i] = cert.Raw } - req.Request.Tls.VerifiedChains = make([]*httpproto.Certificates, len(r.TLS.VerifiedChains)) + req.Request.Tls.VerifiedChains = make([]*ghttpproto.Certificates, len(r.TLS.VerifiedChains)) for i, chain := range r.TLS.VerifiedChains { - req.Request.Tls.VerifiedChains[i] = &httpproto.Certificates{ + req.Request.Tls.VerifiedChains[i] = &ghttpproto.Certificates{ Cert: make([][]byte, len(chain)), } for j, cert := range chain { diff --git a/vms/rpcchainvm/ghttp/http_server.go b/vms/rpcchainvm/ghttp/http_server.go index ae1af60..d8c5d1b 100644 --- a/vms/rpcchainvm/ghttp/http_server.go +++ b/vms/rpcchainvm/ghttp/http_server.go @@ -12,12 +12,11 @@ import ( "github.com/hashicorp/go-plugin" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/ghttpproto" "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greadcloser" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greadcloser/greadcloserproto" "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gresponsewriter" - - readcloserproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/greadcloser/proto" - responsewriterproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gresponsewriter/proto" - httpproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/proto" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/gresponsewriter/gresponsewriterproto" ) // Server is a http.Handler that is managed over RPC. @@ -35,7 +34,7 @@ func NewServer(handler http.Handler, broker *plugin.GRPCBroker) *Server { } // Handle ... -func (s *Server) Handle(ctx context.Context, req *httpproto.HTTPRequest) (*httpproto.HTTPResponse, error) { +func (s *Server) Handle(ctx context.Context, req *ghttpproto.HTTPRequest) (*ghttpproto.HTTPResponse, error) { writerConn, err := s.broker.Dial(req.ResponseWriter) if err != nil { return nil, err @@ -48,8 +47,8 @@ func (s *Server) Handle(ctx context.Context, req *httpproto.HTTPRequest) (*httpp } defer readerConn.Close() - writer := gresponsewriter.NewClient(responsewriterproto.NewWriterClient(writerConn), s.broker) - reader := greadcloser.NewClient(readcloserproto.NewReaderClient(readerConn)) + writer := gresponsewriter.NewClient(gresponsewriterproto.NewWriterClient(writerConn), s.broker) + reader := greadcloser.NewClient(greadcloserproto.NewReaderClient(readerConn)) // create the request with the current context request, err := http.NewRequestWithContext( @@ -143,5 +142,5 @@ func (s *Server) Handle(ctx context.Context, req *httpproto.HTTPRequest) (*httpp s.handler.ServeHTTP(writer, request) // return the response - return &httpproto.HTTPResponse{}, nil + return &ghttpproto.HTTPResponse{}, nil } diff --git a/vms/rpcchainvm/messenger/messenger_client.go b/vms/rpcchainvm/messenger/messenger_client.go index f8f8033..dc1a9d4 100644 --- a/vms/rpcchainvm/messenger/messenger_client.go +++ b/vms/rpcchainvm/messenger/messenger_client.go @@ -7,20 +7,22 @@ import ( "context" "github.com/ava-labs/gecko/snow/engine/common" - "github.com/ava-labs/gecko/vms/rpcchainvm/messenger/proto" + "github.com/ava-labs/gecko/vms/rpcchainvm/messenger/messengerproto" ) // Client is an implementation of a messenger channel that talks over RPC. -type Client struct{ client proto.MessengerClient } +type Client struct { + client messengerproto.MessengerClient +} // NewClient returns a database instance connected to a remote database instance -func NewClient(client proto.MessengerClient) *Client { +func NewClient(client messengerproto.MessengerClient) *Client { return &Client{client: client} } // Notify ... func (c *Client) Notify(msg common.Message) error { - _, err := c.client.Notify(context.Background(), &proto.NotifyRequest{ + _, err := c.client.Notify(context.Background(), &messengerproto.NotifyRequest{ Message: uint32(msg), }) return err diff --git a/vms/rpcchainvm/messenger/messenger_server.go b/vms/rpcchainvm/messenger/messenger_server.go index a051d7b..5358472 100644 --- a/vms/rpcchainvm/messenger/messenger_server.go +++ b/vms/rpcchainvm/messenger/messenger_server.go @@ -8,7 +8,7 @@ import ( "errors" "github.com/ava-labs/gecko/snow/engine/common" - "github.com/ava-labs/gecko/vms/rpcchainvm/messenger/proto" + "github.com/ava-labs/gecko/vms/rpcchainvm/messenger/messengerproto" ) var ( @@ -26,11 +26,11 @@ func NewServer(messenger chan<- common.Message) *Server { } // Notify ... -func (s *Server) Notify(_ context.Context, req *proto.NotifyRequest) (*proto.NotifyResponse, error) { +func (s *Server) Notify(_ context.Context, req *messengerproto.NotifyRequest) (*messengerproto.NotifyResponse, error) { msg := common.Message(req.Message) select { case s.messenger <- msg: - return &proto.NotifyResponse{}, nil + return &messengerproto.NotifyResponse{}, nil default: return nil, errFullQueue } diff --git a/vms/rpcchainvm/messenger/proto/messenger.pb.go b/vms/rpcchainvm/messenger/messengerproto/messenger.pb.go similarity index 85% rename from vms/rpcchainvm/messenger/proto/messenger.pb.go rename to vms/rpcchainvm/messenger/messengerproto/messenger.pb.go index 35dd59c..2d26b30 100644 --- a/vms/rpcchainvm/messenger/proto/messenger.pb.go +++ b/vms/rpcchainvm/messenger/messengerproto/messenger.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // source: messenger.proto -package proto +package messengerproto import ( context "context" @@ -95,22 +95,22 @@ func (m *NotifyResponse) XXX_DiscardUnknown() { var xxx_messageInfo_NotifyResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*NotifyRequest)(nil), "proto.NotifyRequest") - proto.RegisterType((*NotifyResponse)(nil), "proto.NotifyResponse") + proto.RegisterType((*NotifyRequest)(nil), "messengerproto.NotifyRequest") + proto.RegisterType((*NotifyResponse)(nil), "messengerproto.NotifyResponse") } func init() { proto.RegisterFile("messenger.proto", fileDescriptor_b99aba0cbf4e4b91) } var fileDescriptor_b99aba0cbf4e4b91 = []byte{ - // 123 bytes of a gzipped FileDescriptorProto + // 126 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xcf, 0x4d, 0x2d, 0x2e, - 0x4e, 0xcd, 0x4b, 0x4f, 0x2d, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, 0x4a, - 0x9a, 0x5c, 0xbc, 0x7e, 0xf9, 0x25, 0x99, 0x69, 0x95, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, - 0x42, 0x12, 0x5c, 0xec, 0x20, 0xa5, 0x89, 0xe9, 0xa9, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0xbc, 0x41, - 0x30, 0xae, 0x92, 0x00, 0x17, 0x1f, 0x4c, 0x69, 0x71, 0x41, 0x7e, 0x5e, 0x71, 0xaa, 0x91, 0x13, - 0x17, 0xa7, 0x2f, 0xcc, 0x58, 0x21, 0x53, 0x2e, 0x36, 0x88, 0xb4, 0x90, 0x08, 0xc4, 0x0a, 0x3d, - 0x14, 0x83, 0xa5, 0x44, 0xd1, 0x44, 0x21, 0x66, 0x24, 0xb1, 0x81, 0x45, 0x8d, 0x01, 0x01, 0x00, - 0x00, 0xff, 0xff, 0x39, 0x03, 0x19, 0x97, 0xa1, 0x00, 0x00, 0x00, + 0x4e, 0xcd, 0x4b, 0x4f, 0x2d, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x83, 0x0b, 0x80, + 0xf9, 0x4a, 0x9a, 0x5c, 0xbc, 0x7e, 0xf9, 0x25, 0x99, 0x69, 0x95, 0x41, 0xa9, 0x85, 0xa5, 0xa9, + 0xc5, 0x25, 0x42, 0x12, 0x5c, 0xec, 0x20, 0x25, 0x89, 0xe9, 0xa9, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, + 0xbc, 0x41, 0x30, 0xae, 0x92, 0x00, 0x17, 0x1f, 0x4c, 0x69, 0x71, 0x41, 0x7e, 0x5e, 0x71, 0xaa, + 0x51, 0x08, 0x17, 0xa7, 0x2f, 0xcc, 0x38, 0x21, 0x77, 0x2e, 0x36, 0x88, 0xb4, 0x90, 0xac, 0x1e, + 0xaa, 0x25, 0x7a, 0x28, 0x36, 0x48, 0xc9, 0xe1, 0x92, 0x86, 0x98, 0x9a, 0xc4, 0x06, 0x16, 0x35, + 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x0b, 0xb8, 0x8d, 0x52, 0xbc, 0x00, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -138,7 +138,7 @@ func NewMessengerClient(cc grpc.ClientConnInterface) MessengerClient { func (c *messengerClient) Notify(ctx context.Context, in *NotifyRequest, opts ...grpc.CallOption) (*NotifyResponse, error) { out := new(NotifyResponse) - err := c.cc.Invoke(ctx, "/proto.Messenger/Notify", in, out, opts...) + err := c.cc.Invoke(ctx, "/messengerproto.Messenger/Notify", in, out, opts...) if err != nil { return nil, err } @@ -172,7 +172,7 @@ func _Messenger_Notify_Handler(srv interface{}, ctx context.Context, dec func(in } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Messenger/Notify", + FullMethod: "/messengerproto.Messenger/Notify", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MessengerServer).Notify(ctx, req.(*NotifyRequest)) @@ -181,7 +181,7 @@ func _Messenger_Notify_Handler(srv interface{}, ctx context.Context, dec func(in } var _Messenger_serviceDesc = grpc.ServiceDesc{ - ServiceName: "proto.Messenger", + ServiceName: "messengerproto.Messenger", HandlerType: (*MessengerServer)(nil), Methods: []grpc.MethodDesc{ { diff --git a/vms/rpcchainvm/messenger/proto/messenger.proto b/vms/rpcchainvm/messenger/messengerproto/messenger.proto similarity index 87% rename from vms/rpcchainvm/messenger/proto/messenger.proto rename to vms/rpcchainvm/messenger/messengerproto/messenger.proto index b1cb02b..7e44448 100644 --- a/vms/rpcchainvm/messenger/proto/messenger.proto +++ b/vms/rpcchainvm/messenger/messengerproto/messenger.proto @@ -1,5 +1,5 @@ syntax = "proto3"; -package proto; +package messengerproto; message NotifyRequest { uint32 message = 1; diff --git a/vms/rpcchainvm/vm.go b/vms/rpcchainvm/vm.go index 083fbd3..4289b90 100644 --- a/vms/rpcchainvm/vm.go +++ b/vms/rpcchainvm/vm.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/go-plugin" "github.com/ava-labs/gecko/snow/engine/snowman" - "github.com/ava-labs/gecko/vms/rpcchainvm/proto" + "github.com/ava-labs/gecko/vms/rpcchainvm/vmproto" ) // Handshake is a common handshake that is shared by plugin and host. @@ -40,11 +40,11 @@ func New(vm snowman.ChainVM) *Plugin { return &Plugin{vm: vm} } // GRPCServer ... func (p *Plugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error { - proto.RegisterVMServer(s, NewServer(p.vm, broker)) + vmproto.RegisterVMServer(s, NewServer(p.vm, broker)) return nil } // GRPCClient ... func (p *Plugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) { - return NewClient(proto.NewVMClient(c), broker), nil + return NewClient(vmproto.NewVMClient(c), broker), nil } diff --git a/vms/rpcchainvm/vm_client.go b/vms/rpcchainvm/vm_client.go index 098241e..be55496 100644 --- a/vms/rpcchainvm/vm_client.go +++ b/vms/rpcchainvm/vm_client.go @@ -14,6 +14,7 @@ import ( "github.com/ava-labs/gecko/database" "github.com/ava-labs/gecko/database/rpcdb" + "github.com/ava-labs/gecko/database/rpcdb/rpcdbproto" "github.com/ava-labs/gecko/ids" "github.com/ava-labs/gecko/snow" "github.com/ava-labs/gecko/snow/choices" @@ -21,12 +22,10 @@ import ( "github.com/ava-labs/gecko/snow/engine/common" "github.com/ava-labs/gecko/vms/components/missing" "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/ghttpproto" "github.com/ava-labs/gecko/vms/rpcchainvm/messenger" - - dbproto "github.com/ava-labs/gecko/database/rpcdb/proto" - httpproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/proto" - msgproto "github.com/ava-labs/gecko/vms/rpcchainvm/messenger/proto" - vmproto "github.com/ava-labs/gecko/vms/rpcchainvm/proto" + "github.com/ava-labs/gecko/vms/rpcchainvm/messenger/messengerproto" + "github.com/ava-labs/gecko/vms/rpcchainvm/vmproto" ) var ( @@ -109,7 +108,7 @@ func (vm *VMClient) startDBServer(opts []grpc.ServerOption) *grpc.Server { vm.servers = append(vm.servers, server) } - dbproto.RegisterDatabaseServer(server, vm.db) + rpcdbproto.RegisterDatabaseServer(server, vm.db) return server } @@ -125,7 +124,7 @@ func (vm *VMClient) startMessengerServer(opts []grpc.ServerOption) *grpc.Server vm.servers = append(vm.servers, server) } - msgproto.RegisterMessengerServer(server, vm.messenger) + messengerproto.RegisterMessengerServer(server, vm.messenger) return server } @@ -172,7 +171,7 @@ func (vm *VMClient) CreateHandlers() map[string]*common.HTTPHandler { vm.conns = append(vm.conns, conn) handlers[handler.Prefix] = &common.HTTPHandler{ LockOptions: common.LockOption(handler.LockOptions), - Handler: ghttp.NewClient(httpproto.NewHTTPClient(conn), vm.broker), + Handler: ghttp.NewClient(ghttpproto.NewHTTPClient(conn), vm.broker), } } return handlers diff --git a/vms/rpcchainvm/vm_server.go b/vms/rpcchainvm/vm_server.go index e83a957..1a24704 100644 --- a/vms/rpcchainvm/vm_server.go +++ b/vms/rpcchainvm/vm_server.go @@ -12,18 +12,17 @@ import ( "github.com/hashicorp/go-plugin" "github.com/ava-labs/gecko/database/rpcdb" + "github.com/ava-labs/gecko/database/rpcdb/rpcdbproto" "github.com/ava-labs/gecko/ids" "github.com/ava-labs/gecko/snow" "github.com/ava-labs/gecko/snow/engine/common" "github.com/ava-labs/gecko/snow/engine/snowman" "github.com/ava-labs/gecko/utils/wrappers" "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp" + "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/ghttpproto" "github.com/ava-labs/gecko/vms/rpcchainvm/messenger" - - dbproto "github.com/ava-labs/gecko/database/rpcdb/proto" - httpproto "github.com/ava-labs/gecko/vms/rpcchainvm/ghttp/proto" - msgproto "github.com/ava-labs/gecko/vms/rpcchainvm/messenger/proto" - vmproto "github.com/ava-labs/gecko/vms/rpcchainvm/proto" + "github.com/ava-labs/gecko/vms/rpcchainvm/messenger/messengerproto" + "github.com/ava-labs/gecko/vms/rpcchainvm/vmproto" ) // VMServer is a VM that is managed over RPC. @@ -59,8 +58,8 @@ func (vm *VMServer) Initialize(_ context.Context, req *vmproto.InitializeRequest return nil, err } - dbClient := rpcdb.NewClient(dbproto.NewDatabaseClient(dbConn)) - msgClient := messenger.NewClient(msgproto.NewMessengerClient(msgConn)) + dbClient := rpcdb.NewClient(rpcdbproto.NewDatabaseClient(dbConn)) + msgClient := messenger.NewClient(messengerproto.NewMessengerClient(msgConn)) toEngine := make(chan common.Message, 1) go func() { @@ -127,7 +126,7 @@ func (vm *VMServer) CreateHandlers(_ context.Context, req *vmproto.CreateHandler vm.servers = append(vm.servers, server) } - httpproto.RegisterHTTPServer(server, ghttp.NewServer(handler.Handler, vm.broker)) + ghttpproto.RegisterHTTPServer(server, ghttp.NewServer(handler.Handler, vm.broker)) return server }) diff --git a/vms/rpcchainvm/proto/vm.pb.go b/vms/rpcchainvm/vmproto/vm.pb.go similarity index 87% rename from vms/rpcchainvm/proto/vm.pb.go rename to vms/rpcchainvm/vmproto/vm.pb.go index f39e89d..55093bb 100644 --- a/vms/rpcchainvm/proto/vm.pb.go +++ b/vms/rpcchainvm/vmproto/vm.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // source: vm.proto -package proto +package vmproto import ( context "context" @@ -922,74 +922,74 @@ func (m *BlockRejectResponse) XXX_DiscardUnknown() { var xxx_messageInfo_BlockRejectResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*InitializeRequest)(nil), "proto.InitializeRequest") - proto.RegisterType((*InitializeResponse)(nil), "proto.InitializeResponse") - proto.RegisterType((*ShutdownRequest)(nil), "proto.ShutdownRequest") - proto.RegisterType((*ShutdownResponse)(nil), "proto.ShutdownResponse") - proto.RegisterType((*CreateHandlersRequest)(nil), "proto.CreateHandlersRequest") - proto.RegisterType((*CreateHandlersResponse)(nil), "proto.CreateHandlersResponse") - proto.RegisterType((*Handler)(nil), "proto.Handler") - proto.RegisterType((*BuildBlockRequest)(nil), "proto.BuildBlockRequest") - proto.RegisterType((*BuildBlockResponse)(nil), "proto.BuildBlockResponse") - proto.RegisterType((*ParseBlockRequest)(nil), "proto.ParseBlockRequest") - proto.RegisterType((*ParseBlockResponse)(nil), "proto.ParseBlockResponse") - proto.RegisterType((*GetBlockRequest)(nil), "proto.GetBlockRequest") - proto.RegisterType((*GetBlockResponse)(nil), "proto.GetBlockResponse") - proto.RegisterType((*SetPreferenceRequest)(nil), "proto.SetPreferenceRequest") - proto.RegisterType((*SetPreferenceResponse)(nil), "proto.SetPreferenceResponse") - proto.RegisterType((*LastAcceptedRequest)(nil), "proto.LastAcceptedRequest") - proto.RegisterType((*LastAcceptedResponse)(nil), "proto.LastAcceptedResponse") - proto.RegisterType((*BlockVerifyRequest)(nil), "proto.BlockVerifyRequest") - proto.RegisterType((*BlockVerifyResponse)(nil), "proto.BlockVerifyResponse") - proto.RegisterType((*BlockAcceptRequest)(nil), "proto.BlockAcceptRequest") - proto.RegisterType((*BlockAcceptResponse)(nil), "proto.BlockAcceptResponse") - proto.RegisterType((*BlockRejectRequest)(nil), "proto.BlockRejectRequest") - proto.RegisterType((*BlockRejectResponse)(nil), "proto.BlockRejectResponse") + proto.RegisterType((*InitializeRequest)(nil), "vmproto.InitializeRequest") + proto.RegisterType((*InitializeResponse)(nil), "vmproto.InitializeResponse") + proto.RegisterType((*ShutdownRequest)(nil), "vmproto.ShutdownRequest") + proto.RegisterType((*ShutdownResponse)(nil), "vmproto.ShutdownResponse") + proto.RegisterType((*CreateHandlersRequest)(nil), "vmproto.CreateHandlersRequest") + proto.RegisterType((*CreateHandlersResponse)(nil), "vmproto.CreateHandlersResponse") + proto.RegisterType((*Handler)(nil), "vmproto.Handler") + proto.RegisterType((*BuildBlockRequest)(nil), "vmproto.BuildBlockRequest") + proto.RegisterType((*BuildBlockResponse)(nil), "vmproto.BuildBlockResponse") + proto.RegisterType((*ParseBlockRequest)(nil), "vmproto.ParseBlockRequest") + proto.RegisterType((*ParseBlockResponse)(nil), "vmproto.ParseBlockResponse") + proto.RegisterType((*GetBlockRequest)(nil), "vmproto.GetBlockRequest") + proto.RegisterType((*GetBlockResponse)(nil), "vmproto.GetBlockResponse") + proto.RegisterType((*SetPreferenceRequest)(nil), "vmproto.SetPreferenceRequest") + proto.RegisterType((*SetPreferenceResponse)(nil), "vmproto.SetPreferenceResponse") + proto.RegisterType((*LastAcceptedRequest)(nil), "vmproto.LastAcceptedRequest") + proto.RegisterType((*LastAcceptedResponse)(nil), "vmproto.LastAcceptedResponse") + proto.RegisterType((*BlockVerifyRequest)(nil), "vmproto.BlockVerifyRequest") + proto.RegisterType((*BlockVerifyResponse)(nil), "vmproto.BlockVerifyResponse") + proto.RegisterType((*BlockAcceptRequest)(nil), "vmproto.BlockAcceptRequest") + proto.RegisterType((*BlockAcceptResponse)(nil), "vmproto.BlockAcceptResponse") + proto.RegisterType((*BlockRejectRequest)(nil), "vmproto.BlockRejectRequest") + proto.RegisterType((*BlockRejectResponse)(nil), "vmproto.BlockRejectResponse") } func init() { proto.RegisterFile("vm.proto", fileDescriptor_cab246c8c7c5372d) } var fileDescriptor_cab246c8c7c5372d = []byte{ - // 610 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x4b, 0x6f, 0xd3, 0x40, - 0x10, 0x96, 0x53, 0xb5, 0x84, 0xc9, 0xa3, 0xcd, 0xe6, 0x89, 0x5b, 0xa4, 0x60, 0xa1, 0x2a, 0x70, - 0xe8, 0xa1, 0x1c, 0x7b, 0x4a, 0x88, 0x54, 0x8a, 0xa8, 0xa8, 0x1c, 0x29, 0x42, 0x82, 0x8b, 0x13, - 0x4f, 0x5a, 0x43, 0xb0, 0x8d, 0x77, 0xd3, 0x52, 0xfe, 0x3b, 0x12, 0x8a, 0x3d, 0x5e, 0xef, 0xda, - 0x8e, 0x2a, 0x71, 0xb2, 0x66, 0xe6, 0x9b, 0x6f, 0x1e, 0x3b, 0x9f, 0xa1, 0x7a, 0xff, 0xf3, 0x2c, - 0x8c, 0x02, 0x11, 0xb0, 0xfd, 0xf8, 0x63, 0x3d, 0x40, 0xeb, 0xca, 0xf7, 0x84, 0xe7, 0xac, 0xbd, - 0x3f, 0x68, 0xe3, 0xaf, 0x0d, 0x72, 0xc1, 0x4c, 0xa8, 0xba, 0x8b, 0x19, 0x46, 0xf7, 0x18, 0x0d, - 0x8c, 0xa1, 0x31, 0x6a, 0xd8, 0xd2, 0x66, 0x16, 0xd4, 0x6f, 0xd1, 0x47, 0xee, 0xf1, 0xc9, 0xa3, - 0x40, 0x3e, 0xa8, 0x0c, 0x8d, 0x51, 0xdd, 0xd6, 0x7c, 0x5b, 0x0c, 0xfa, 0xb7, 0x9e, 0x8f, 0xc4, - 0xb1, 0x17, 0x73, 0x68, 0x3e, 0xab, 0x03, 0x4c, 0x2d, 0xcc, 0xc3, 0xc0, 0xe7, 0x68, 0xb5, 0xe0, - 0x70, 0x76, 0xb7, 0x11, 0x6e, 0xf0, 0xe0, 0x53, 0x33, 0x16, 0x83, 0xa3, 0xcc, 0x45, 0xb0, 0x3e, - 0x74, 0xdf, 0x47, 0xe8, 0x08, 0xfc, 0xe0, 0xf8, 0xee, 0x1a, 0x23, 0x9e, 0x82, 0xa7, 0xd0, 0xcb, - 0x07, 0x92, 0x14, 0xf6, 0x16, 0xaa, 0x77, 0xe4, 0x1b, 0x18, 0xc3, 0xbd, 0x51, 0xed, 0xbc, 0x99, - 0x6c, 0xe2, 0x8c, 0xa0, 0xb6, 0x8c, 0x5b, 0x5f, 0xe1, 0x19, 0x39, 0x59, 0x0f, 0x0e, 0xc2, 0x08, - 0x57, 0xde, 0xef, 0x78, 0x11, 0xcf, 0x6d, 0xb2, 0xd8, 0x10, 0x6a, 0xeb, 0x60, 0xf9, 0xe3, 0x73, - 0x28, 0xbc, 0xc0, 0x4f, 0xb6, 0xd0, 0xb0, 0x55, 0xd7, 0x36, 0x93, 0xab, 0xe3, 0x93, 0x65, 0xb5, - 0xa1, 0x35, 0xd9, 0x78, 0x6b, 0x77, 0xb2, 0x05, 0xa7, 0x7d, 0xcf, 0x81, 0xa9, 0x4e, 0xea, 0xb9, - 0x09, 0x15, 0xcf, 0x8d, 0x0b, 0xd7, 0xed, 0x8a, 0xe7, 0x6e, 0xdf, 0x25, 0x74, 0x22, 0xf4, 0xc5, - 0xd5, 0x94, 0xf6, 0x2e, 0x6d, 0xd6, 0x81, 0xfd, 0x45, 0xfc, 0x20, 0x7b, 0x71, 0x20, 0x31, 0xac, - 0x37, 0xd0, 0xba, 0x71, 0x22, 0x8e, 0x6a, 0xb1, 0x0c, 0x6a, 0xa8, 0xd0, 0x2f, 0xc0, 0x54, 0xe8, - 0x7f, 0xb4, 0xb0, 0x9d, 0x58, 0x38, 0x62, 0xc3, 0xe5, 0xc4, 0xb1, 0x65, 0xbd, 0x82, 0xc3, 0x4b, - 0x14, 0x5a, 0x0b, 0x39, 0x5a, 0xeb, 0x1b, 0x1c, 0x65, 0x10, 0x2a, 0xad, 0x96, 0x32, 0x76, 0x4d, - 0x5b, 0x51, 0x46, 0xd8, 0xd9, 0xc0, 0x29, 0x74, 0x66, 0x28, 0x6e, 0x22, 0x5c, 0x61, 0x84, 0xfe, - 0x12, 0x77, 0x75, 0xd1, 0x87, 0x6e, 0x0e, 0x47, 0xf7, 0xd6, 0x85, 0xf6, 0x27, 0x87, 0x8b, 0xf1, - 0x72, 0x89, 0xa1, 0x40, 0x37, 0x7d, 0xb5, 0x53, 0xe8, 0xe8, 0xee, 0xf2, 0xa5, 0x59, 0xaf, 0x81, - 0xc5, 0xa3, 0xcd, 0x31, 0xf2, 0x56, 0x8f, 0xbb, 0xaa, 0x77, 0xa1, 0xad, 0xa1, 0xa8, 0x76, 0x9a, - 0x9c, 0x54, 0x79, 0x2a, 0x39, 0x45, 0xe5, 0x92, 0x6d, 0xfc, 0x8e, 0xcb, 0x27, 0x93, 0x53, 0x54, - 0x92, 0x7c, 0xfe, 0x77, 0x1f, 0x2a, 0xf3, 0x6b, 0x36, 0x06, 0xc8, 0x94, 0xca, 0x06, 0xa4, 0x9a, - 0xc2, 0x5f, 0xc3, 0x7c, 0x51, 0x12, 0xa1, 0x85, 0x5c, 0x40, 0x35, 0xd5, 0x30, 0xeb, 0x11, 0x2c, - 0xa7, 0x73, 0xb3, 0x5f, 0xf0, 0x53, 0xf2, 0x35, 0x34, 0x75, 0x4d, 0xb3, 0x13, 0x82, 0x96, 0xfe, - 0x03, 0xcc, 0x97, 0x3b, 0xa2, 0x44, 0x37, 0x06, 0xc8, 0xa4, 0x26, 0xc7, 0x29, 0x48, 0x52, 0x8e, - 0x53, 0xa2, 0xcb, 0x31, 0x40, 0x26, 0x15, 0x49, 0x51, 0x10, 0x9a, 0xa4, 0x28, 0xd1, 0xd5, 0x05, - 0x54, 0xd3, 0x83, 0x97, 0x1b, 0xc9, 0x89, 0x44, 0x6e, 0xa4, 0xa0, 0x8c, 0x8f, 0xd0, 0xd0, 0xee, - 0x94, 0x1d, 0xa7, 0xbb, 0x2b, 0xb9, 0x72, 0xf3, 0xa4, 0x3c, 0x48, 0x5c, 0x97, 0x50, 0x57, 0x6f, - 0x98, 0x99, 0x84, 0x2e, 0xb9, 0x77, 0xf3, 0xb8, 0x34, 0x46, 0x44, 0x53, 0xa8, 0x29, 0xe7, 0xcb, - 0xe4, 0xfa, 0x0a, 0x87, 0x6f, 0x9a, 0x65, 0xa1, 0x1c, 0x4b, 0x42, 0xaf, 0xb3, 0x68, 0x0a, 0xd0, - 0x59, 0xf4, 0xb3, 0x97, 0x2c, 0xc9, 0x41, 0xeb, 0x2c, 0x9a, 0x14, 0x74, 0x16, 0xfd, 0xfe, 0x17, - 0x07, 0x71, 0xe8, 0xdd, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x10, 0x57, 0x73, 0x31, 0x35, 0x07, - 0x00, 0x00, + // 617 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x6d, 0x6f, 0xd2, 0x50, + 0x14, 0x4e, 0x21, 0x32, 0x3c, 0xc0, 0x06, 0x17, 0xd8, 0xb0, 0x6e, 0x13, 0x1b, 0xb3, 0x60, 0x62, + 0xf8, 0x30, 0x7f, 0xc0, 0x22, 0x8a, 0x6e, 0xf1, 0x6d, 0x96, 0x84, 0x98, 0xe8, 0x97, 0x42, 0x0f, + 0x5b, 0x95, 0xb5, 0xf5, 0xde, 0x0b, 0x73, 0xfe, 0x23, 0xff, 0xa5, 0xa1, 0xbd, 0x6d, 0xef, 0xbd, + 0xb4, 0x59, 0xe2, 0xb7, 0x9e, 0x73, 0x9e, 0xf3, 0x9c, 0x97, 0x7b, 0x9e, 0x42, 0x75, 0x7d, 0x33, + 0x0c, 0x69, 0xc0, 0x03, 0xb2, 0xb3, 0xbe, 0x89, 0x3e, 0xac, 0x5b, 0x68, 0x5d, 0xf8, 0x1e, 0xf7, + 0x9c, 0xa5, 0xf7, 0x07, 0x6d, 0xfc, 0xb5, 0x42, 0xc6, 0x89, 0x09, 0x55, 0x77, 0x36, 0x41, 0xba, + 0x46, 0xda, 0x33, 0xfa, 0xc6, 0xa0, 0x61, 0xa7, 0x36, 0xb1, 0xa0, 0x7e, 0x85, 0x3e, 0x32, 0x8f, + 0x8d, 0xee, 0x38, 0xb2, 0x5e, 0xa9, 0x6f, 0x0c, 0xea, 0xb6, 0xe2, 0xdb, 0x60, 0xd0, 0xbf, 0xf2, + 0x7c, 0x14, 0x1c, 0xe5, 0x88, 0x43, 0xf1, 0x59, 0x1d, 0x20, 0x72, 0x61, 0x16, 0x06, 0x3e, 0x43, + 0xab, 0x05, 0x7b, 0x93, 0xeb, 0x15, 0x77, 0x83, 0x5b, 0x5f, 0x34, 0x63, 0x11, 0x68, 0x66, 0x2e, + 0x01, 0x3b, 0x80, 0xee, 0x6b, 0x8a, 0x0e, 0xc7, 0x73, 0xc7, 0x77, 0x97, 0x48, 0x59, 0x02, 0x7e, + 0x0b, 0xfb, 0x7a, 0x20, 0x4e, 0x21, 0x2f, 0xa0, 0x7a, 0x2d, 0x7c, 0x3d, 0xa3, 0x5f, 0x1e, 0xd4, + 0x4e, 0x9b, 0x43, 0xb1, 0x84, 0xa1, 0x00, 0xdb, 0x29, 0xc2, 0xfa, 0x06, 0x3b, 0xc2, 0x49, 0xf6, + 0xa1, 0x12, 0x52, 0x5c, 0x78, 0xbf, 0xa3, 0x55, 0x3c, 0xb4, 0x85, 0x45, 0xfa, 0x50, 0x5b, 0x06, + 0xf3, 0x9f, 0x9f, 0x43, 0xee, 0x05, 0x7e, 0xbc, 0x87, 0x86, 0x2d, 0xbb, 0x36, 0x99, 0x4c, 0x5e, + 0x80, 0xb0, 0xac, 0x36, 0xb4, 0x46, 0x2b, 0x6f, 0xe9, 0x8e, 0x36, 0xe0, 0xa4, 0xf3, 0x29, 0x10, + 0xd9, 0x29, 0xba, 0xde, 0x85, 0x92, 0xe7, 0x46, 0x85, 0xeb, 0x76, 0xc9, 0x73, 0x37, 0x2f, 0x13, + 0x3a, 0x14, 0x7d, 0x7e, 0xf1, 0x46, 0x6c, 0x3e, 0xb5, 0x49, 0x07, 0x1e, 0xcc, 0xa2, 0x27, 0x29, + 0x47, 0x81, 0xd8, 0xb0, 0x9e, 0x43, 0xeb, 0xd2, 0xa1, 0x0c, 0xe5, 0x62, 0x19, 0xd4, 0x90, 0xa1, + 0x5f, 0x81, 0xc8, 0xd0, 0xff, 0x68, 0x61, 0x33, 0x31, 0x77, 0xf8, 0x8a, 0xa5, 0x13, 0x47, 0x96, + 0xf5, 0x14, 0xf6, 0xde, 0x21, 0x57, 0x5a, 0xd0, 0x68, 0xad, 0xef, 0xd0, 0xcc, 0x20, 0xa2, 0xb4, + 0x5c, 0xca, 0x28, 0x9a, 0xb6, 0x24, 0x8d, 0x50, 0xd8, 0xc0, 0x09, 0x74, 0x26, 0xc8, 0x2f, 0x29, + 0x2e, 0x90, 0xa2, 0x3f, 0xc7, 0xa2, 0x2e, 0x0e, 0xa0, 0xab, 0xe1, 0xc4, 0xc5, 0x75, 0xa1, 0xfd, + 0xc1, 0x61, 0xfc, 0xd5, 0x7c, 0x8e, 0x21, 0x47, 0x37, 0x79, 0xb5, 0x13, 0xe8, 0xa8, 0xee, 0xfc, + 0xa5, 0x59, 0xcf, 0x80, 0x44, 0xa3, 0x4d, 0x91, 0x7a, 0x8b, 0xbb, 0xa2, 0xea, 0x5d, 0x68, 0x2b, + 0x28, 0x51, 0x3b, 0x49, 0x8e, 0xab, 0xdc, 0x97, 0x9c, 0xa0, 0xb4, 0x64, 0x1b, 0x7f, 0xe0, 0xfc, + 0xde, 0xe4, 0x04, 0x15, 0x27, 0x9f, 0xfe, 0xad, 0x40, 0x69, 0xfa, 0x91, 0x8c, 0x01, 0x32, 0xad, + 0x12, 0x33, 0xd5, 0xcd, 0xd6, 0x9f, 0xc3, 0x7c, 0x9c, 0x1b, 0x13, 0x4b, 0x39, 0x83, 0x6a, 0xa2, + 0x64, 0xd2, 0x4b, 0x81, 0x9a, 0xde, 0xcd, 0x47, 0x39, 0x11, 0x41, 0xf0, 0x05, 0x76, 0x55, 0x75, + 0x93, 0xe3, 0x14, 0x9c, 0xfb, 0x3f, 0x30, 0x9f, 0x14, 0xc6, 0x05, 0xe5, 0x18, 0x20, 0x93, 0x9d, + 0x34, 0xda, 0x96, 0x40, 0xa5, 0xd1, 0x72, 0x74, 0x3a, 0x06, 0xc8, 0xa4, 0x23, 0xd1, 0x6c, 0x49, + 0x4f, 0xa2, 0xc9, 0xd1, 0xda, 0x19, 0x54, 0x13, 0x11, 0x48, 0x1b, 0xd2, 0xa4, 0x23, 0x6d, 0x68, + 0x4b, 0x31, 0x9f, 0xa0, 0xa1, 0xdc, 0x2f, 0x39, 0xca, 0xb6, 0x99, 0x73, 0xff, 0xe6, 0x71, 0x51, + 0x58, 0xf0, 0xbd, 0x87, 0xba, 0x7c, 0xdf, 0xe4, 0x30, 0xc5, 0xe7, 0xa8, 0xc1, 0x3c, 0x2a, 0x88, + 0x0a, 0xb2, 0x73, 0xa8, 0x49, 0xe7, 0x4d, 0xa4, 0x85, 0x6e, 0x49, 0xc3, 0x3c, 0xcc, 0x0f, 0x6a, + 0x4c, 0x71, 0x09, 0x9d, 0x49, 0xd1, 0x89, 0xce, 0xa4, 0xca, 0x23, 0x65, 0x8a, 0x0f, 0x5f, 0x67, + 0x52, 0x44, 0xa3, 0x33, 0xa9, 0x5a, 0x99, 0x55, 0xa2, 0xd0, 0xcb, 0x7f, 0x01, 0x00, 0x00, 0xff, + 0xff, 0xbb, 0xac, 0x5b, 0xc8, 0x65, 0x07, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1027,7 +1027,7 @@ func NewVMClient(cc grpc.ClientConnInterface) VMClient { func (c *vMClient) Initialize(ctx context.Context, in *InitializeRequest, opts ...grpc.CallOption) (*InitializeResponse, error) { out := new(InitializeResponse) - err := c.cc.Invoke(ctx, "/proto.VM/Initialize", in, out, opts...) + err := c.cc.Invoke(ctx, "/vmproto.VM/Initialize", in, out, opts...) if err != nil { return nil, err } @@ -1036,7 +1036,7 @@ func (c *vMClient) Initialize(ctx context.Context, in *InitializeRequest, opts . func (c *vMClient) Shutdown(ctx context.Context, in *ShutdownRequest, opts ...grpc.CallOption) (*ShutdownResponse, error) { out := new(ShutdownResponse) - err := c.cc.Invoke(ctx, "/proto.VM/Shutdown", in, out, opts...) + err := c.cc.Invoke(ctx, "/vmproto.VM/Shutdown", in, out, opts...) if err != nil { return nil, err } @@ -1045,7 +1045,7 @@ func (c *vMClient) Shutdown(ctx context.Context, in *ShutdownRequest, opts ...gr func (c *vMClient) CreateHandlers(ctx context.Context, in *CreateHandlersRequest, opts ...grpc.CallOption) (*CreateHandlersResponse, error) { out := new(CreateHandlersResponse) - err := c.cc.Invoke(ctx, "/proto.VM/CreateHandlers", in, out, opts...) + err := c.cc.Invoke(ctx, "/vmproto.VM/CreateHandlers", in, out, opts...) if err != nil { return nil, err } @@ -1054,7 +1054,7 @@ func (c *vMClient) CreateHandlers(ctx context.Context, in *CreateHandlersRequest func (c *vMClient) BuildBlock(ctx context.Context, in *BuildBlockRequest, opts ...grpc.CallOption) (*BuildBlockResponse, error) { out := new(BuildBlockResponse) - err := c.cc.Invoke(ctx, "/proto.VM/BuildBlock", in, out, opts...) + err := c.cc.Invoke(ctx, "/vmproto.VM/BuildBlock", in, out, opts...) if err != nil { return nil, err } @@ -1063,7 +1063,7 @@ func (c *vMClient) BuildBlock(ctx context.Context, in *BuildBlockRequest, opts . func (c *vMClient) ParseBlock(ctx context.Context, in *ParseBlockRequest, opts ...grpc.CallOption) (*ParseBlockResponse, error) { out := new(ParseBlockResponse) - err := c.cc.Invoke(ctx, "/proto.VM/ParseBlock", in, out, opts...) + err := c.cc.Invoke(ctx, "/vmproto.VM/ParseBlock", in, out, opts...) if err != nil { return nil, err } @@ -1072,7 +1072,7 @@ func (c *vMClient) ParseBlock(ctx context.Context, in *ParseBlockRequest, opts . func (c *vMClient) GetBlock(ctx context.Context, in *GetBlockRequest, opts ...grpc.CallOption) (*GetBlockResponse, error) { out := new(GetBlockResponse) - err := c.cc.Invoke(ctx, "/proto.VM/GetBlock", in, out, opts...) + err := c.cc.Invoke(ctx, "/vmproto.VM/GetBlock", in, out, opts...) if err != nil { return nil, err } @@ -1081,7 +1081,7 @@ func (c *vMClient) GetBlock(ctx context.Context, in *GetBlockRequest, opts ...gr func (c *vMClient) SetPreference(ctx context.Context, in *SetPreferenceRequest, opts ...grpc.CallOption) (*SetPreferenceResponse, error) { out := new(SetPreferenceResponse) - err := c.cc.Invoke(ctx, "/proto.VM/SetPreference", in, out, opts...) + err := c.cc.Invoke(ctx, "/vmproto.VM/SetPreference", in, out, opts...) if err != nil { return nil, err } @@ -1090,7 +1090,7 @@ func (c *vMClient) SetPreference(ctx context.Context, in *SetPreferenceRequest, func (c *vMClient) LastAccepted(ctx context.Context, in *LastAcceptedRequest, opts ...grpc.CallOption) (*LastAcceptedResponse, error) { out := new(LastAcceptedResponse) - err := c.cc.Invoke(ctx, "/proto.VM/LastAccepted", in, out, opts...) + err := c.cc.Invoke(ctx, "/vmproto.VM/LastAccepted", in, out, opts...) if err != nil { return nil, err } @@ -1099,7 +1099,7 @@ func (c *vMClient) LastAccepted(ctx context.Context, in *LastAcceptedRequest, op func (c *vMClient) BlockVerify(ctx context.Context, in *BlockVerifyRequest, opts ...grpc.CallOption) (*BlockVerifyResponse, error) { out := new(BlockVerifyResponse) - err := c.cc.Invoke(ctx, "/proto.VM/BlockVerify", in, out, opts...) + err := c.cc.Invoke(ctx, "/vmproto.VM/BlockVerify", in, out, opts...) if err != nil { return nil, err } @@ -1108,7 +1108,7 @@ func (c *vMClient) BlockVerify(ctx context.Context, in *BlockVerifyRequest, opts func (c *vMClient) BlockAccept(ctx context.Context, in *BlockAcceptRequest, opts ...grpc.CallOption) (*BlockAcceptResponse, error) { out := new(BlockAcceptResponse) - err := c.cc.Invoke(ctx, "/proto.VM/BlockAccept", in, out, opts...) + err := c.cc.Invoke(ctx, "/vmproto.VM/BlockAccept", in, out, opts...) if err != nil { return nil, err } @@ -1117,7 +1117,7 @@ func (c *vMClient) BlockAccept(ctx context.Context, in *BlockAcceptRequest, opts func (c *vMClient) BlockReject(ctx context.Context, in *BlockRejectRequest, opts ...grpc.CallOption) (*BlockRejectResponse, error) { out := new(BlockRejectResponse) - err := c.cc.Invoke(ctx, "/proto.VM/BlockReject", in, out, opts...) + err := c.cc.Invoke(ctx, "/vmproto.VM/BlockReject", in, out, opts...) if err != nil { return nil, err } @@ -1191,7 +1191,7 @@ func _VM_Initialize_Handler(srv interface{}, ctx context.Context, dec func(inter } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.VM/Initialize", + FullMethod: "/vmproto.VM/Initialize", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(VMServer).Initialize(ctx, req.(*InitializeRequest)) @@ -1209,7 +1209,7 @@ func _VM_Shutdown_Handler(srv interface{}, ctx context.Context, dec func(interfa } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.VM/Shutdown", + FullMethod: "/vmproto.VM/Shutdown", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(VMServer).Shutdown(ctx, req.(*ShutdownRequest)) @@ -1227,7 +1227,7 @@ func _VM_CreateHandlers_Handler(srv interface{}, ctx context.Context, dec func(i } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.VM/CreateHandlers", + FullMethod: "/vmproto.VM/CreateHandlers", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(VMServer).CreateHandlers(ctx, req.(*CreateHandlersRequest)) @@ -1245,7 +1245,7 @@ func _VM_BuildBlock_Handler(srv interface{}, ctx context.Context, dec func(inter } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.VM/BuildBlock", + FullMethod: "/vmproto.VM/BuildBlock", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(VMServer).BuildBlock(ctx, req.(*BuildBlockRequest)) @@ -1263,7 +1263,7 @@ func _VM_ParseBlock_Handler(srv interface{}, ctx context.Context, dec func(inter } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.VM/ParseBlock", + FullMethod: "/vmproto.VM/ParseBlock", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(VMServer).ParseBlock(ctx, req.(*ParseBlockRequest)) @@ -1281,7 +1281,7 @@ func _VM_GetBlock_Handler(srv interface{}, ctx context.Context, dec func(interfa } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.VM/GetBlock", + FullMethod: "/vmproto.VM/GetBlock", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(VMServer).GetBlock(ctx, req.(*GetBlockRequest)) @@ -1299,7 +1299,7 @@ func _VM_SetPreference_Handler(srv interface{}, ctx context.Context, dec func(in } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.VM/SetPreference", + FullMethod: "/vmproto.VM/SetPreference", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(VMServer).SetPreference(ctx, req.(*SetPreferenceRequest)) @@ -1317,7 +1317,7 @@ func _VM_LastAccepted_Handler(srv interface{}, ctx context.Context, dec func(int } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.VM/LastAccepted", + FullMethod: "/vmproto.VM/LastAccepted", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(VMServer).LastAccepted(ctx, req.(*LastAcceptedRequest)) @@ -1335,7 +1335,7 @@ func _VM_BlockVerify_Handler(srv interface{}, ctx context.Context, dec func(inte } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.VM/BlockVerify", + FullMethod: "/vmproto.VM/BlockVerify", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(VMServer).BlockVerify(ctx, req.(*BlockVerifyRequest)) @@ -1353,7 +1353,7 @@ func _VM_BlockAccept_Handler(srv interface{}, ctx context.Context, dec func(inte } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.VM/BlockAccept", + FullMethod: "/vmproto.VM/BlockAccept", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(VMServer).BlockAccept(ctx, req.(*BlockAcceptRequest)) @@ -1371,7 +1371,7 @@ func _VM_BlockReject_Handler(srv interface{}, ctx context.Context, dec func(inte } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.VM/BlockReject", + FullMethod: "/vmproto.VM/BlockReject", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(VMServer).BlockReject(ctx, req.(*BlockRejectRequest)) @@ -1380,7 +1380,7 @@ func _VM_BlockReject_Handler(srv interface{}, ctx context.Context, dec func(inte } var _VM_serviceDesc = grpc.ServiceDesc{ - ServiceName: "proto.VM", + ServiceName: "vmproto.VM", HandlerType: (*VMServer)(nil), Methods: []grpc.MethodDesc{ { diff --git a/vms/rpcchainvm/proto/vm.proto b/vms/rpcchainvm/vmproto/vm.proto similarity index 99% rename from vms/rpcchainvm/proto/vm.proto rename to vms/rpcchainvm/vmproto/vm.proto index 649c66b..7834805 100644 --- a/vms/rpcchainvm/proto/vm.proto +++ b/vms/rpcchainvm/vmproto/vm.proto @@ -1,5 +1,5 @@ syntax = "proto3"; -package proto; +package vmproto; message InitializeRequest { uint32 dbServer = 1; From c3230b9e46aee8466822c7c025e20159071ecc6c Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Fri, 17 Apr 2020 10:39:08 -0400 Subject: [PATCH 20/61] Resolve nil pointer error on the rpcchainvm --- vms/rpcchainvm/vm_client.go | 1 + 1 file changed, 1 insertion(+) diff --git a/vms/rpcchainvm/vm_client.go b/vms/rpcchainvm/vm_client.go index be55496..0698432 100644 --- a/vms/rpcchainvm/vm_client.go +++ b/vms/rpcchainvm/vm_client.go @@ -55,6 +55,7 @@ func NewClient(client vmproto.VMClient, broker *plugin.GRPCBroker) *VMClient { return &VMClient{ client: client, broker: broker, + blks: make(map[[32]byte]*BlockClient), } } From 77341d622fd32699118a7d5a227a140fd1929cb3 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 17 Apr 2020 18:13:30 -0400 Subject: [PATCH 21/61] change SN to chain in chain logs --- utils/logging/factory.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/logging/factory.go b/utils/logging/factory.go index 112d03c..c5d5f60 100644 --- a/utils/logging/factory.go +++ b/utils/logging/factory.go @@ -43,7 +43,7 @@ func (f *factory) Make() (Logger, error) { // MakeChain ... func (f *factory) MakeChain(chainID ids.ID, subdir string) (Logger, error) { config := f.config - config.MsgPrefix = "SN " + chainID.String() + config.MsgPrefix = "chain " + chainID.String() config.Directory = path.Join(config.Directory, "chain", chainID.String(), subdir) log, err := New(config) From 0f6cad33b179fbbf46e2fc87060d23507612ceae Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Sat, 18 Apr 2020 18:43:14 +0100 Subject: [PATCH 22/61] vms: Add test for avm.VM.Format --- vms/avm/vm_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/vms/avm/vm_test.go b/vms/avm/vm_test.go index cfd09e8..6655d15 100644 --- a/vms/avm/vm_test.go +++ b/vms/avm/vm_test.go @@ -934,3 +934,51 @@ func TestIssueProperty(t *testing.T) { t.Fatal(err) } } + +func TestVMFormat(t *testing.T) { + _, _, vm := GenesisVM(t) + defer ctx.Lock.Unlock() + defer vm.Shutdown() + + tests := []struct { + in string + expected string + }{ + {"", "3D7sudhzUKTYFkYj4Zoe7GgSKhuyP9bYwXunHwhZsmQe1z9Mp-45PJLL"}, + } + for _, tt := range tests { + t.Run(tt.in, func(t *testing.T) { + if res := vm.Format([]byte(tt.in)); tt.expected != res { + t.Errorf("Expected %q, got %q", tt.expected, res) + } + }) + } +} + +func TestVMFormatAliased(t *testing.T) { + _, _, vm := GenesisVM(t) + defer ctx.Lock.Unlock() + defer vm.Shutdown() + + origAliases := ctx.BCLookup + defer func() { ctx.BCLookup = origAliases }() + + tmpAliases := &ids.Aliaser{} + tmpAliases.Initialize() + tmpAliases.Alias(ctx.ChainID, "X") + ctx.BCLookup = tmpAliases + + tests := []struct { + in string + expected string + }{ + {"", "X-45PJLL"}, + } + for _, tt := range tests { + t.Run(tt.in, func(t *testing.T) { + if res := vm.Format([]byte(tt.in)); tt.expected != res { + t.Errorf("Expected %q, got %q", tt.expected, res) + } + }) + } +} From 1092abe8446983e1759c7130e0036eed3308e506 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Sat, 18 Apr 2020 20:34:19 -0400 Subject: [PATCH 23/61] Changed to support 1-way connections --- api/admin/networking.go | 4 +- networking/addrset.go | 288 ------------------------------- networking/builder.go | 3 +- networking/commands.go | 9 +- networking/connections.go | 264 ++++++++++++++++++++++++++++ networking/handshake_handlers.go | 183 ++++++++++---------- networking/voting_handlers.go | 128 +++++++------- node/node.go | 11 +- utils/ip.go | 42 +++++ 9 files changed, 470 insertions(+), 462 deletions(-) delete mode 100644 networking/addrset.go create mode 100644 networking/connections.go diff --git a/api/admin/networking.go b/api/admin/networking.go index ef564e6..3207e46 100644 --- a/api/admin/networking.go +++ b/api/admin/networking.go @@ -10,14 +10,14 @@ import ( ) // Peerable can return a group of peers -type Peerable interface{ Peers() []utils.IPDesc } +type Peerable interface{ IPs() []utils.IPDesc } // Networking provides helper methods for tracking the current network state type Networking struct{ peers Peerable } // Peers returns the current peers func (n *Networking) Peers() ([]string, error) { - ipDescs := n.peers.Peers() + ipDescs := n.peers.IPs() ips := make([]string, len(ipDescs)) for i, ipDesc := range ipDescs { ips[i] = ipDesc.String() diff --git a/networking/addrset.go b/networking/addrset.go deleted file mode 100644 index a03e0df..0000000 --- a/networking/addrset.go +++ /dev/null @@ -1,288 +0,0 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package networking - -import ( - "fmt" - "sync" - - "github.com/ava-labs/salticidae-go" - - "github.com/ava-labs/gecko/ids" - "github.com/ava-labs/gecko/utils" -) - -// Connections provides an interface for what a group of connections will -// support. -type Connections interface { - Add(salticidae.NetAddr, ids.ShortID) - - GetIP(ids.ShortID) (salticidae.NetAddr, bool) - GetID(salticidae.NetAddr) (ids.ShortID, bool) - - ContainsIP(salticidae.NetAddr) bool - ContainsID(ids.ShortID) bool - - Remove(salticidae.NetAddr, ids.ShortID) - RemoveIP(salticidae.NetAddr) - RemoveID(ids.ShortID) - - Peers() []utils.IPDesc - IPs() []salticidae.NetAddr - IDs() ids.ShortSet - Conns() ([]utils.IPDesc, []ids.ShortID) - RawConns() ([]salticidae.NetAddr, []ids.ShortID) - - Len() int -} - -// AddrCert implements the Connections interface -type AddrCert struct { - // ip -> id - ipToID map[uint64]ids.ShortID - // id -> ip - idToIP map[[20]byte]salticidae.NetAddr - mux sync.Mutex -} - -// Add Assumes that addr is garbage collected normally -func (ac *AddrCert) Add(ip salticidae.NetAddr, id ids.ShortID) { - ac.mux.Lock() - defer ac.mux.Unlock() - - ac.add(ip, id) -} - -// GetIP returns the ip mapped to the id that is provided if one exists. -func (ac *AddrCert) GetIP(id ids.ShortID) (salticidae.NetAddr, bool) { - ac.mux.Lock() - defer ac.mux.Unlock() - - return ac.getIP(id) -} - -// GetID returns the id mapped to the ip that is provided if one exists. -func (ac *AddrCert) GetID(ip salticidae.NetAddr) (ids.ShortID, bool) { - ac.mux.Lock() - defer ac.mux.Unlock() - - return ac.getID(ip) -} - -// ContainsIP returns true if the ip is contained in the connection pool -func (ac *AddrCert) ContainsIP(ip salticidae.NetAddr) bool { - _, exists := ac.GetID(ip) - return exists -} - -// ContainsID returns true if the id is contained in the connection pool -func (ac *AddrCert) ContainsID(id ids.ShortID) bool { - _, exists := ac.GetIP(id) - return exists -} - -// Remove ensures that no connection will have any mapping containing [ip] or -// [id]. -func (ac *AddrCert) Remove(ip salticidae.NetAddr, id ids.ShortID) { - ac.mux.Lock() - defer ac.mux.Unlock() - - ac.remove(ip, id) -} - -// RemoveIP ensures that no connection will have a mapping containing [ip] -func (ac *AddrCert) RemoveIP(ip salticidae.NetAddr) { - ac.mux.Lock() - defer ac.mux.Unlock() - - ac.removeIP(ip) -} - -// RemoveID ensures that no connection will have a mapping containing [id] -func (ac *AddrCert) RemoveID(id ids.ShortID) { - ac.mux.Lock() - defer ac.mux.Unlock() - - ac.removeID(id) -} - -// Peers returns the full list of ips contained in this connection pool. -func (ac *AddrCert) Peers() []utils.IPDesc { - ac.mux.Lock() - defer ac.mux.Unlock() - - return ac.peers() -} - -// IPs returns the full list of ips contained in this connection pool. This can -// be useful for gossiping a node's connections through the network. -func (ac *AddrCert) IPs() []salticidae.NetAddr { - ac.mux.Lock() - defer ac.mux.Unlock() - - return ac.ips() -} - -// IDs return the set of IDs that are mapping in this connection pool. -func (ac *AddrCert) IDs() ids.ShortSet { - ac.mux.Lock() - defer ac.mux.Unlock() - - return ac.ids() -} - -// Conns return the set of connections in this connection pool. -func (ac *AddrCert) Conns() ([]utils.IPDesc, []ids.ShortID) { - ac.mux.Lock() - defer ac.mux.Unlock() - - return ac.conns() -} - -// RawConns return the set of connections in this connection pool. -func (ac *AddrCert) RawConns() ([]salticidae.NetAddr, []ids.ShortID) { - ac.mux.Lock() - defer ac.mux.Unlock() - - return ac.rawConns() -} - -// Len returns the number of elements in the map -func (ac *AddrCert) Len() int { - ac.mux.Lock() - defer ac.mux.Unlock() - - return ac.len() -} - -func (ac *AddrCert) init() { - if ac.ipToID == nil { - ac.ipToID = make(map[uint64]ids.ShortID) - } - if ac.idToIP == nil { - ac.idToIP = make(map[[20]byte]salticidae.NetAddr) - } -} - -func (ac *AddrCert) add(ip salticidae.NetAddr, id ids.ShortID) { - ac.init() - - ac.removeIP(ip) - ac.removeID(id) - - ac.ipToID[addrToID(ip)] = id - ac.idToIP[id.Key()] = ip -} - -func (ac *AddrCert) getIP(id ids.ShortID) (salticidae.NetAddr, bool) { - ac.init() - - ip, exists := ac.idToIP[id.Key()] - return ip, exists -} - -func (ac *AddrCert) getID(ip salticidae.NetAddr) (ids.ShortID, bool) { - ac.init() - - id, exists := ac.ipToID[addrToID(ip)] - return id, exists -} - -func (ac *AddrCert) remove(ip salticidae.NetAddr, id ids.ShortID) { - ac.removeIP(ip) - ac.removeID(id) -} - -func (ac *AddrCert) removeIP(ip salticidae.NetAddr) { - ac.init() - - ipID := addrToID(ip) - if id, exists := ac.ipToID[ipID]; exists { - delete(ac.ipToID, ipID) - delete(ac.idToIP, id.Key()) - } -} - -func (ac *AddrCert) removeID(id ids.ShortID) { - ac.init() - - idKey := id.Key() - if ip, exists := ac.idToIP[idKey]; exists { - delete(ac.ipToID, addrToID(ip)) - delete(ac.idToIP, idKey) - } -} - -func (ac *AddrCert) peers() []utils.IPDesc { - ac.init() - - ips := []utils.IPDesc(nil) - for _, ip := range ac.idToIP { - ips = append(ips, toIPDesc(ip)) - } - return ips -} - -func (ac *AddrCert) ips() []salticidae.NetAddr { - ac.init() - - ips := []salticidae.NetAddr(nil) - for _, ip := range ac.idToIP { - ips = append(ips, ip) - } - return ips -} - -func (ac *AddrCert) ids() ids.ShortSet { - ac.init() - - ids := ids.ShortSet{} - for _, id := range ac.ipToID { - ids.Add(id) - } - return ids -} - -func (ac *AddrCert) conns() ([]utils.IPDesc, []ids.ShortID) { - ac.init() - - ipList := []utils.IPDesc(nil) - idList := []ids.ShortID(nil) - for id, ip := range ac.idToIP { - ipList = append(ipList, toIPDesc(ip)) - idList = append(idList, ids.NewShortID(id)) - } - return ipList, idList -} - -func (ac *AddrCert) rawConns() ([]salticidae.NetAddr, []ids.ShortID) { - ac.init() - - ipList := []salticidae.NetAddr(nil) - idList := []ids.ShortID(nil) - for id, ip := range ac.idToIP { - ipList = append(ipList, ip) - idList = append(idList, ids.NewShortID(id)) - } - return ipList, idList -} - -func (ac *AddrCert) len() int { return len(ac.ipToID) } - -func toIPDesc(addr salticidae.NetAddr) utils.IPDesc { - ip, err := ToIPDesc(addr) - HandshakeNet.log.AssertNoError(err) - return ip -} - -// ToIPDesc converts an address to an IP -func ToIPDesc(addr salticidae.NetAddr) (utils.IPDesc, error) { - ip := salticidae.FromBigEndianU32(addr.GetIP()) - port := salticidae.FromBigEndianU16(addr.GetPort()) - return utils.ToIPDesc(fmt.Sprintf("%d.%d.%d.%d:%d", byte(ip>>24), byte(ip>>16), byte(ip>>8), byte(ip), port)) -} - -func addrToID(addr salticidae.NetAddr) uint64 { - return uint64(addr.GetIP()) | (uint64(addr.GetPort()) << 32) -} diff --git a/networking/builder.go b/networking/builder.go index cbe451b..7d7f83a 100644 --- a/networking/builder.go +++ b/networking/builder.go @@ -16,10 +16,11 @@ type Builder struct{ Codec } func (m Builder) GetVersion() (Msg, error) { return m.Pack(GetVersion, nil) } // Version message -func (m Builder) Version(networkID uint32, myTime uint64, myVersion string) (Msg, error) { +func (m Builder) Version(networkID uint32, myTime uint64, ip utils.IPDesc, myVersion string) (Msg, error) { return m.Pack(Version, map[Field]interface{}{ NetworkID: networkID, MyTime: myTime, + IP: ip, VersionStr: myVersion, }) } diff --git a/networking/commands.go b/networking/commands.go index ffb5cbb..d2b610a 100644 --- a/networking/commands.go +++ b/networking/commands.go @@ -17,6 +17,7 @@ const ( VersionStr Field = iota // Used in handshake NetworkID // Used in handshake MyTime // Used in handshake + IP // Used in handshake Peers // Used in handshake ChainID // Used for dispatching RequestID // Used for all messages @@ -38,6 +39,8 @@ func (f Field) Packer() func(*wrappers.Packer, interface{}) { return wrappers.TryPackInt case MyTime: return wrappers.TryPackLong + case IP: + return wrappers.TryPackIP case Peers: return wrappers.TryPackIPList case ChainID: // TODO: This will be shortened to use a modified varint spec @@ -72,6 +75,8 @@ func (f Field) Unpacker() func(*wrappers.Packer) interface{} { return wrappers.TryUnpackInt case MyTime: return wrappers.TryUnpackLong + case IP: + return wrappers.TryUnpackIP case Peers: return wrappers.TryUnpackIPList case ChainID: // TODO: This will be shortened to use a modified varint spec @@ -105,6 +110,8 @@ func (f Field) String() string { return "NetworkID" case MyTime: return "MyTime" + case IP: + return "IP" case Peers: return "Peers" case ChainID: @@ -161,7 +168,7 @@ var ( Messages = map[salticidae.Opcode][]Field{ // Handshake: GetVersion: []Field{}, - Version: []Field{NetworkID, MyTime, VersionStr}, + Version: []Field{NetworkID, MyTime, IP, VersionStr}, GetPeerList: []Field{}, PeerList: []Field{Peers}, // Bootstrapping: diff --git a/networking/connections.go b/networking/connections.go new file mode 100644 index 0000000..7b6a6ea --- /dev/null +++ b/networking/connections.go @@ -0,0 +1,264 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package networking + +import ( + "fmt" + "sync" + + "github.com/ava-labs/salticidae-go" + + "github.com/ava-labs/gecko/ids" + "github.com/ava-labs/gecko/utils" +) + +// Connections provides an interface for what a group of connections will +// support. +type Connections interface { + Add(salticidae.PeerID, ids.ShortID, utils.IPDesc) + + GetPeerID(ids.ShortID) (salticidae.PeerID, bool) + GetID(salticidae.PeerID) (ids.ShortID, bool) + + ContainsPeerID(salticidae.PeerID) bool + ContainsID(ids.ShortID) bool + ContainsIP(utils.IPDesc) bool + + Remove(salticidae.PeerID, ids.ShortID) + RemovePeerID(salticidae.PeerID) + RemoveID(ids.ShortID) + + PeerIDs() []salticidae.PeerID + IDs() ids.ShortSet + IPs() []utils.IPDesc + Conns() ([]salticidae.PeerID, []ids.ShortID, []utils.IPDesc) + + Len() int +} + +type connections struct { + mux sync.Mutex + // peerID -> id + peerIDToID map[[32]byte]ids.ShortID + // id -> peerID + idToPeerID map[[20]byte]salticidae.PeerID + // id -> ip + idToIP map[[20]byte]utils.IPDesc +} + +// NewConnections returns a new and empty connections object +func NewConnections() Connections { + return &connections{ + peerIDToID: make(map[[32]byte]ids.ShortID), + idToPeerID: make(map[[20]byte]salticidae.PeerID), + idToIP: make(map[[20]byte]utils.IPDesc), + } +} + +// Add Assumes that peer is garbage collected normally +func (c *connections) Add(peer salticidae.PeerID, id ids.ShortID, ip utils.IPDesc) { + c.mux.Lock() + defer c.mux.Unlock() + + c.add(peer, id, ip) +} + +// GetPeerID returns the peer mapped to the id that is provided if one exists. +func (c *connections) GetPeerID(id ids.ShortID) (salticidae.PeerID, bool) { + c.mux.Lock() + defer c.mux.Unlock() + + return c.getPeerID(id) +} + +// GetID returns the id mapped to the peer that is provided if one exists. +func (c *connections) GetID(peer salticidae.PeerID) (ids.ShortID, bool) { + c.mux.Lock() + defer c.mux.Unlock() + + return c.getID(peer) +} + +// ContainsPeerID returns true if the peer is contained in the connection pool +func (c *connections) ContainsPeerID(peer salticidae.PeerID) bool { + _, exists := c.GetID(peer) + return exists +} + +// ContainsID returns true if the id is contained in the connection pool +func (c *connections) ContainsID(id ids.ShortID) bool { + _, exists := c.GetPeerID(id) + return exists +} + +// ContainsIP returns true if the ip is contained in the connection pool +func (c *connections) ContainsIP(ip utils.IPDesc) bool { + for _, otherIP := range c.IPs() { + if ip.Equal(otherIP) { + return true + } + } + return false +} + +// Remove ensures that no connection will have any mapping containing [peer] or +// [id]. +func (c *connections) Remove(peer salticidae.PeerID, id ids.ShortID) { + c.mux.Lock() + defer c.mux.Unlock() + + c.remove(peer, id) +} + +// RemovePeerID ensures that no connection will have a mapping containing [peer] +func (c *connections) RemovePeerID(peer salticidae.PeerID) { + c.mux.Lock() + defer c.mux.Unlock() + + c.removePeerID(peer) +} + +// RemoveID ensures that no connection will have a mapping containing [id] +func (c *connections) RemoveID(id ids.ShortID) { + c.mux.Lock() + defer c.mux.Unlock() + + c.removeID(id) +} + +// PeerIDs returns the full list of peers contained in this connection pool. +func (c *connections) PeerIDs() []salticidae.PeerID { + c.mux.Lock() + defer c.mux.Unlock() + + return c.peerIDs() +} + +// IDs return the set of IDs that are mapping in this connection pool. +func (c *connections) IDs() ids.ShortSet { + c.mux.Lock() + defer c.mux.Unlock() + + return c.ids() +} + +// IPs return the set of IPs that are mapped in this connection pool. +func (c *connections) IPs() []utils.IPDesc { + c.mux.Lock() + defer c.mux.Unlock() + + return c.ips() +} + +// Conns return the set of connections in this connection pool. +func (c *connections) Conns() ([]salticidae.PeerID, []ids.ShortID, []utils.IPDesc) { + c.mux.Lock() + defer c.mux.Unlock() + + return c.conns() +} + +// Len returns the number of elements in the map +func (c *connections) Len() int { + c.mux.Lock() + defer c.mux.Unlock() + + return c.len() +} + +func (c *connections) add(peer salticidae.PeerID, id ids.ShortID, ip utils.IPDesc) { + c.remove(peer, id) + + key := id.Key() + c.peerIDToID[toID(peer)] = id + c.idToPeerID[key] = peer + c.idToIP[key] = ip +} + +func (c *connections) getPeerID(id ids.ShortID) (salticidae.PeerID, bool) { + peer, exists := c.idToPeerID[id.Key()] + return peer, exists +} + +func (c *connections) getID(peer salticidae.PeerID) (ids.ShortID, bool) { + id, exists := c.peerIDToID[toID(peer)] + return id, exists +} + +func (c *connections) remove(peer salticidae.PeerID, id ids.ShortID) { + c.removePeerID(peer) + c.removeID(id) +} + +func (c *connections) removePeerID(peer salticidae.PeerID) { + peerID := toID(peer) + if id, exists := c.peerIDToID[peerID]; exists { + delete(c.peerIDToID, peerID) + delete(c.idToPeerID, id.Key()) + } +} + +func (c *connections) removeID(id ids.ShortID) { + idKey := id.Key() + if peer, exists := c.idToPeerID[idKey]; exists { + delete(c.peerIDToID, toID(peer)) + delete(c.idToPeerID, idKey) + } +} + +func (c *connections) peerIDs() []salticidae.PeerID { + peers := make([]salticidae.PeerID, 0, len(c.idToPeerID)) + for _, peer := range c.idToPeerID { + peers = append(peers, peer) + } + return peers +} + +func (c *connections) ids() ids.ShortSet { + ids := ids.ShortSet{} + for _, id := range c.peerIDToID { + ids.Add(id) + } + return ids +} + +func (c *connections) ips() []utils.IPDesc { + ips := make([]utils.IPDesc, 0, len(c.idToIP)) + for _, ip := range c.idToIP { + ips = append(ips, ip) + } + return ips +} + +func (c *connections) conns() ([]salticidae.PeerID, []ids.ShortID, []utils.IPDesc) { + peers := make([]salticidae.PeerID, 0, len(c.idToPeerID)) + idList := make([]ids.ShortID, 0, len(c.idToPeerID)) + ips := make([]utils.IPDesc, 0, len(c.idToPeerID)) + for id, peer := range c.idToPeerID { + idList = append(idList, ids.NewShortID(id)) + peers = append(peers, peer) + ips = append(ips, c.idToIP[id]) + } + return peers, idList, ips +} + +func (c *connections) len() int { return len(c.idToPeerID) } + +func toID(peer salticidae.PeerID) [32]byte { + // TODO: need to get the hash from the peer + return [32]byte{} +} + +func toIPDesc(addr salticidae.NetAddr) utils.IPDesc { + ip, err := ToIPDesc(addr) + HandshakeNet.log.AssertNoError(err) + return ip +} + +// ToIPDesc converts an address to an IP +func ToIPDesc(addr salticidae.NetAddr) (utils.IPDesc, error) { + ip := salticidae.FromBigEndianU32(addr.GetIP()) + port := salticidae.FromBigEndianU16(addr.GetPort()) + return utils.ToIPDesc(fmt.Sprintf("%d.%d.%d.%d:%d", byte(ip>>24), byte(ip>>16), byte(ip>>8), byte(ip), port)) +} diff --git a/networking/handshake_handlers.go b/networking/handshake_handlers.go index de6bb9c..f602162 100644 --- a/networking/handshake_handlers.go +++ b/networking/handshake_handlers.go @@ -106,8 +106,8 @@ type Handshake struct { enableStaking bool // Should only be false for local tests clock timer.Clock - pending AddrCert // Connections that I haven't gotten version messages from - connections AddrCert // Connections that I think are connected + pending Connections // Connections that I haven't gotten version messages from + connections Connections // Connections that I think are connected versionTimeout timer.TimeoutManager reconnectTimeout timer.TimeoutManager @@ -138,6 +138,9 @@ func (nm *Handshake) Initialize( nm.enableStaking = enableStaking nm.networkID = networkID + nm.pending = NewConnections() + nm.connections = NewConnections() + net := peerNet.AsMsgNetwork() net.RegConnHandler(salticidae.MsgNetworkConnCallback(C.checkPeerCertificate), nil) @@ -209,19 +212,19 @@ func (nm *Handshake) gossipPeerList() { idsToSend = append(idsToSend, nonStakers[sampler.Sample()]) } - ips := []salticidae.NetAddr{} + peers := []salticidae.PeerID{} for _, id := range idsToSend { - if ip, exists := nm.connections.GetIP(id); exists { - ips = append(ips, ip) + if peer, exists := nm.connections.GetPeerID(id); exists { + peers = append(peers, peer) } } - nm.SendPeerList(ips...) + nm.SendPeerList(peers...) } // Connections returns the object that tracks the nodes that are currently // connected to this node. -func (nm *Handshake) Connections() Connections { return &nm.connections } +func (nm *Handshake) Connections() Connections { return nm.connections } // Shutdown the network func (nm *Handshake) Shutdown() { @@ -230,59 +233,60 @@ func (nm *Handshake) Shutdown() { } // SendGetVersion to the requested peer -func (nm *Handshake) SendGetVersion(addr salticidae.NetAddr) { +func (nm *Handshake) SendGetVersion(peer salticidae.PeerID) { build := Builder{} gv, err := build.GetVersion() nm.log.AssertNoError(err) - nm.send(gv, addr) + nm.send(gv, peer) nm.numGetVersionSent.Inc() } // SendVersion to the requested peer -func (nm *Handshake) SendVersion(addr salticidae.NetAddr) error { +func (nm *Handshake) SendVersion(peer salticidae.PeerID) error { build := Builder{} - v, err := build.Version(nm.networkID, nm.clock.Unix(), CurrentVersion) + v, err := build.Version(nm.networkID, nm.clock.Unix(), toIPDesc(nm.myAddr), CurrentVersion) if err != nil { return fmt.Errorf("packing Version failed due to %s", err) } - nm.send(v, addr) + nm.send(v, peer) nm.numVersionSent.Inc() return nil } // SendPeerList to the requested peer -func (nm *Handshake) SendPeerList(addrs ...salticidae.NetAddr) error { - if len(addrs) == 0 { +func (nm *Handshake) SendPeerList(peers ...salticidae.PeerID) error { + if len(peers) == 0 { return nil } - ips, ids := nm.connections.Conns() + _, ids, ips := nm.connections.Conns() ipsToSend := []utils.IPDesc(nil) for i, id := range ids { - if nm.vdrs.Contains(id) { - ipsToSend = append(ipsToSend, ips[i]) + ip := ips[i] + if !ip.IsPrivate() && nm.vdrs.Contains(id) { + ipsToSend = append(ipsToSend, ip) } } if len(ipsToSend) == 0 { - nm.log.Debug("No IPs to send to %d peer(s)", len(addrs)) + nm.log.Debug("No IPs to send to %d peer(s)", len(peers)) return nil } - nm.log.Verbo("Sending %d ips to %d peer(s)", len(ipsToSend), len(addrs)) + nm.log.Verbo("Sending %d ips to %d peer(s)", len(ipsToSend), len(peers)) build := Builder{} pl, err := build.PeerList(ipsToSend) if err != nil { return fmt.Errorf("Packing Peerlist failed due to %w", err) } - nm.send(pl, addrs...) - nm.numPeerlistSent.Add(float64(len(addrs))) + nm.send(pl, peers...) + nm.numPeerlistSent.Add(float64(len(peers))) return nil } -func (nm *Handshake) send(msg Msg, addrs ...salticidae.NetAddr) { +func (nm *Handshake) send(msg Msg, peers ...salticidae.PeerID) { ds := msg.DataStream() defer ds.Free() ba := salticidae.NewByteArrayMovedFromDataStream(ds, false) @@ -290,12 +294,12 @@ func (nm *Handshake) send(msg Msg, addrs ...salticidae.NetAddr) { cMsg := salticidae.NewMsgMovedFromByteArray(msg.Op(), ba, false) defer cMsg.Free() - switch len(addrs) { + switch len(peers) { case 0: case 1: - nm.net.SendMsg(cMsg, addrs[0]) + nm.net.SendMsg(cMsg, peers[0]) default: - nm.net.MulticastMsgByMove(cMsg, addrs) + nm.net.MulticastMsgByMove(cMsg, peers) } } @@ -305,7 +309,7 @@ func checkPeerCertificate(_ *C.struct_msgnetwork_conn_t, connected C.bool, _ uns return connected } -func (nm *Handshake) connectedToPeer(conn *C.struct_peernetwork_conn_t, addr salticidae.NetAddr) { +func (nm *Handshake) connectedToPeer(conn *C.struct_peernetwork_conn_t, peer salticidae.PeerID, addr salticidae.NetAddr) { ip := toIPDesc(addr) // If we're enforcing staking, use a peer's certificate to uniquely identify them // Otherwise, use a hash of their ip to identify them @@ -323,23 +327,23 @@ func (nm *Handshake) connectedToPeer(conn *C.struct_peernetwork_conn_t, addr sal nm.reconnectTimeout.Remove(longCert) nm.reconnectTimeout.Remove(ipCert.LongID()) - nm.pending.Add(addr, cert) + nm.pending.Add(peer, cert, utils.IPDesc{}) handler := new(func()) *handler = func() { - if nm.pending.ContainsIP(addr) { - nm.SendGetVersion(addr) + if nm.pending.ContainsPeerID(peer) { + nm.SendGetVersion(peer) nm.versionTimeout.Put(longCert, *handler) } } (*handler)() } -func (nm *Handshake) disconnectedFromPeer(addr salticidae.NetAddr) { +func (nm *Handshake) disconnectedFromPeer(peer salticidae.PeerID, addr salticidae.NetAddr) { cert := ids.ShortID{} - if pendingCert, exists := nm.pending.GetID(addr); exists { + if pendingCert, exists := nm.pending.GetID(peer); exists { cert = pendingCert - } else if connectedCert, exists := nm.connections.GetID(addr); exists { + } else if connectedCert, exists := nm.connections.GetID(peer); exists { cert = connectedCert } else { return @@ -350,10 +354,10 @@ func (nm *Handshake) disconnectedFromPeer(addr salticidae.NetAddr) { longCert := cert.LongID() if nm.vdrs.Contains(cert) { nm.reconnectTimeout.Put(longCert, func() { - nm.net.DelPeer(addr) + nm.net.DelPeer(peer) }) } else { - nm.net.DelPeer(addr) + nm.net.DelPeer(peer) } nm.versionTimeout.Remove(longCert) @@ -361,8 +365,8 @@ func (nm *Handshake) disconnectedFromPeer(addr salticidae.NetAddr) { nm.vdrs.Remove(cert) } - nm.pending.RemoveIP(addr) - nm.connections.RemoveIP(addr) + nm.pending.RemovePeerID(peer) + nm.connections.RemovePeerID(peer) nm.numPeers.Set(float64(nm.connections.Len())) nm.awaitingLock.Lock() @@ -379,11 +383,12 @@ func (nm *Handshake) disconnectedFromPeer(addr salticidae.NetAddr) { func peerHandler(_conn *C.struct_peernetwork_conn_t, connected C.bool, _ unsafe.Pointer) { pConn := salticidae.PeerNetworkConnFromC(salticidae.CPeerNetworkConn(_conn)) addr := pConn.GetPeerAddr(true) + peer := pConn.GetPeerID(true) if connected { - HandshakeNet.connectedToPeer(_conn, addr) + HandshakeNet.connectedToPeer(_conn, peer, addr) } else { - HandshakeNet.disconnectedFromPeer(addr) + HandshakeNet.disconnectedFromPeer(peer, addr) } } @@ -392,37 +397,38 @@ func peerHandler(_conn *C.struct_peernetwork_conn_t, connected C.bool, _ unsafe. func unknownPeerHandler(_addr *C.netaddr_t, _cert *C.x509_t, _ unsafe.Pointer) { addr := salticidae.NetAddrFromC(salticidae.CNetAddr(_addr)).Copy(true) ip := toIPDesc(addr) + HandshakeNet.log.Info("Adding peer %s", ip) - cert := ids.ShortID{} + var peer salticidae.PeerID + id := ids.ShortID{} if HandshakeNet.enableStaking { - cert = getCert(salticidae.X509FromC(salticidae.CX509(_cert))) + cert := salticidae.X509FromC(salticidae.CX509(_cert)) + id = getCert(cert) + peer = salticidae.NewPeerIDFromX509(cert, true) } else { - cert = toShortID(ip) + id = toShortID(ip) + peer = salticidae.NewPeerIDFromNetAddr(addr, true) } - HandshakeNet.reconnectTimeout.Put(cert.LongID(), func() { - HandshakeNet.net.DelPeer(addr) + HandshakeNet.reconnectTimeout.Put(id.LongID(), func() { + HandshakeNet.net.DelPeer(peer) }) - HandshakeNet.net.AddPeer(addr) + HandshakeNet.net.AddPeer(peer) } // ping handles the recept of a ping message //export ping func ping(_ *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe.Pointer) { conn := salticidae.PeerNetworkConnFromC(salticidae.CPeerNetworkConn(_conn)) - addr := conn.GetPeerAddr(false) - defer addr.Free() - if addr.IsNull() { - HandshakeNet.log.Warn("Ping sent from unknown peer") - return - } + peer := conn.GetPeerID(false) + defer peer.Free() build := Builder{} pong, err := build.Pong() HandshakeNet.log.AssertNoError(err) - HandshakeNet.send(pong, addr) + HandshakeNet.send(pong, peer) } // pong handles the recept of a pong message @@ -435,15 +441,10 @@ func getVersion(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsaf HandshakeNet.numGetVersionReceived.Inc() conn := salticidae.PeerNetworkConnFromC(salticidae.CPeerNetworkConn(_conn)) - addr := conn.GetPeerAddr(false) - defer addr.Free() + peer := conn.GetPeerID(false) + defer peer.Free() - if addr.IsNull() { - HandshakeNet.log.Warn("GetVersion sent from unknown peer") - return - } - - HandshakeNet.SendVersion(addr) + HandshakeNet.SendVersion(peer) } // version handles the recept of a version message @@ -453,35 +454,28 @@ func version(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe.P msg := salticidae.MsgFromC(salticidae.CMsg(_msg)) conn := salticidae.PeerNetworkConnFromC(salticidae.CPeerNetworkConn(_conn)) - addr := conn.GetPeerAddr(true) - if addr.IsNull() { - HandshakeNet.log.Warn("Version sent from unknown peer") + peer := conn.GetPeerID(true) + + id, exists := HandshakeNet.pending.GetID(peer) + if !exists { return } - cert := ids.ShortID{} - if HandshakeNet.enableStaking { - cert = getMsgCert(_conn) - } else { - ip := toIPDesc(addr) - cert = toShortID(ip) - } - - defer HandshakeNet.pending.Remove(addr, cert) + defer HandshakeNet.pending.Remove(peer, id) build := Builder{} pMsg, err := build.Parse(Version, msg.GetPayloadByMove()) if err != nil { HandshakeNet.log.Warn("Failed to parse Version message") - HandshakeNet.net.DelPeer(addr) + HandshakeNet.net.DelPeer(peer) return } if networkID := pMsg.Get(NetworkID).(uint32); networkID != HandshakeNet.networkID { HandshakeNet.log.Warn("Peer's network ID doesn't match our networkID: Peer's = %d ; Ours = %d", networkID, HandshakeNet.networkID) - HandshakeNet.net.DelPeer(addr) + HandshakeNet.net.DelPeer(peer) return } @@ -489,26 +483,28 @@ func version(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe.P if peerTime := float64(pMsg.Get(MyTime).(uint64)); math.Abs(peerTime-myTime) > MaxClockDifference.Seconds() { HandshakeNet.log.Warn("Peer's clock is too far out of sync with mine. His = %d, Mine = %d (seconds)", uint64(peerTime), uint64(myTime)) - HandshakeNet.net.DelPeer(addr) + HandshakeNet.net.DelPeer(peer) return } if peerVersion := pMsg.Get(VersionStr).(string); !checkCompatibility(CurrentVersion, peerVersion) { HandshakeNet.log.Warn("Bad version") - HandshakeNet.net.DelPeer(addr) + HandshakeNet.net.DelPeer(peer) return } - HandshakeNet.log.Debug("Finishing handshake with %s", toIPDesc(addr)) + ip := pMsg.Get(IP).(utils.IPDesc) - HandshakeNet.SendPeerList(addr) - HandshakeNet.connections.Add(addr, cert) + HandshakeNet.log.Debug("Finishing handshake with %s", ip) - HandshakeNet.versionTimeout.Remove(cert.LongID()) + HandshakeNet.SendPeerList(peer) + HandshakeNet.connections.Add(peer, id, ip) + + HandshakeNet.versionTimeout.Remove(id.LongID()) if !HandshakeNet.enableStaking { - HandshakeNet.vdrs.Add(validators.NewValidator(cert, 1)) + HandshakeNet.vdrs.Add(validators.NewValidator(id, 1)) } HandshakeNet.numPeers.Set(float64(HandshakeNet.connections.Len())) @@ -518,7 +514,7 @@ func version(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe.P for i := 0; i < len(HandshakeNet.awaiting); i++ { awaiting := HandshakeNet.awaiting[i] - awaiting.Add(cert) + awaiting.Add(id) if !awaiting.Ready() { continue } @@ -539,13 +535,10 @@ func getPeerList(_ *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe. HandshakeNet.numGetPeerlistReceived.Inc() conn := salticidae.PeerNetworkConnFromC(salticidae.CPeerNetworkConn(_conn)) - addr := conn.GetPeerAddr(false) - defer addr.Free() - if addr.IsNull() { - HandshakeNet.log.Warn("GetPeerList sent from unknown peer") - return - } - HandshakeNet.SendPeerList(addr) + peer := conn.GetPeerID(false) + defer peer.Free() + + HandshakeNet.SendPeerList(peer) } // peerList handles the recept of a peerList message @@ -569,15 +562,15 @@ func peerList(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe. addr := salticidae.NewNetAddrFromIPPortString(ip.String(), true, &cErr) if cErr.GetCode() == 0 && !HandshakeNet.myAddr.IsEq(addr) { // Make sure not to connect to myself ip := toIPDesc(addr) - ipCert := toShortID(ip) - - if !HandshakeNet.pending.ContainsIP(addr) && !HandshakeNet.connections.ContainsIP(addr) { + if !HandshakeNet.pending.ContainsIP(ip) && !HandshakeNet.connections.ContainsIP(ip) { HandshakeNet.log.Debug("Adding peer %s", ip) - HandshakeNet.reconnectTimeout.Put(ipCert.LongID(), func() { - HandshakeNet.net.DelPeer(addr) - }) - HandshakeNet.net.AddPeer(addr) + // TODO: Attempt to connect to the IP + // ipCert := toShortID(ip) + // HandshakeNet.reconnectTimeout.Put(ipCert.LongID(), func() { + // HandshakeNet.net.DelPeer(addr) + // }) + // HandshakeNet.net.AddPeer(addr) } } } diff --git a/networking/voting_handlers.go b/networking/voting_handlers.go index 4c7be62..a5746d4 100644 --- a/networking/voting_handlers.go +++ b/networking/voting_handlers.go @@ -89,12 +89,12 @@ func (s *Voting) Shutdown() { s.executor.Stop() } // Accept is called after every consensus decision func (s *Voting) Accept(chainID, containerID ids.ID, container []byte) error { - addrs := []salticidae.NetAddr(nil) + peers := []salticidae.PeerID(nil) - allAddrs, allIDs := s.conns.RawConns() + allPeers, allIDs, _ := s.conns.Conns() for i, id := range allIDs { if !s.vdrs.Contains(id) { - addrs = append(addrs, allAddrs[i]) + peers = append(peers, allPeers[i]) } } @@ -109,25 +109,25 @@ func (s *Voting) Accept(chainID, containerID ids.ID, container []byte) error { "\nChain: %s"+ "\nContainer ID: %s"+ "\nContainer:\n%s", - len(addrs), + len(peers), chainID, containerID, formatting.DumpBytes{Bytes: container}, ) - s.send(msg, addrs...) - s.numPutSent.Add(float64(len(addrs))) + s.send(msg, peers...) + s.numPutSent.Add(float64(len(peers))) return nil } // GetAcceptedFrontier implements the Sender interface. func (s *Voting) GetAcceptedFrontier(validatorIDs ids.ShortSet, chainID ids.ID, requestID uint32) { - addrs := []salticidae.NetAddr(nil) + peers := []salticidae.PeerID(nil) validatorIDList := validatorIDs.List() for _, validatorID := range validatorIDList { vID := validatorID - if addr, exists := s.conns.GetIP(vID); exists { - addrs = append(addrs, addr) - s.log.Verbo("Sending a GetAcceptedFrontier to %s", toIPDesc(addr)) + if peer, exists := s.conns.GetPeerID(vID); exists { + peers = append(peers, peer) + s.log.Verbo("Sending a GetAcceptedFrontier to %s", vID) } else { s.log.Debug("Attempted to send a GetAcceptedFrontier message to a disconnected validator: %s", vID) s.executor.Add(func() { s.router.GetAcceptedFrontierFailed(vID, chainID, requestID) }) @@ -142,17 +142,17 @@ func (s *Voting) GetAcceptedFrontier(validatorIDs ids.ShortSet, chainID ids.ID, "\nNumber of Validators: %d"+ "\nChain: %s"+ "\nRequest ID: %d", - len(addrs), + len(peers), chainID, requestID, ) - s.send(msg, addrs...) - s.numGetAcceptedFrontierSent.Add(float64(len(addrs))) + s.send(msg, peers...) + s.numGetAcceptedFrontierSent.Add(float64(len(peers))) } // AcceptedFrontier implements the Sender interface. func (s *Voting) AcceptedFrontier(validatorID ids.ShortID, chainID ids.ID, requestID uint32, containerIDs ids.Set) { - addr, exists := s.conns.GetIP(validatorID) + peer, exists := s.conns.GetPeerID(validatorID) if !exists { s.log.Debug("Attempted to send an AcceptedFrontier message to a disconnected validator: %s", validatorID) return // Validator is not connected @@ -167,29 +167,27 @@ func (s *Voting) AcceptedFrontier(validatorID ids.ShortID, chainID ids.ID, reque s.log.Verbo("Sending an AcceptedFrontier message."+ "\nValidator: %s"+ - "\nDestination: %s"+ "\nChain: %s"+ "\nRequest ID: %d"+ "\nContainer IDs: %s", validatorID, - toIPDesc(addr), chainID, requestID, containerIDs, ) - s.send(msg, addr) + s.send(msg, peer) s.numAcceptedFrontierSent.Inc() } // GetAccepted implements the Sender interface. func (s *Voting) GetAccepted(validatorIDs ids.ShortSet, chainID ids.ID, requestID uint32, containerIDs ids.Set) { - addrs := []salticidae.NetAddr(nil) + peers := []salticidae.PeerID(nil) validatorIDList := validatorIDs.List() for _, validatorID := range validatorIDList { vID := validatorID - if addr, exists := s.conns.GetIP(validatorID); exists { - addrs = append(addrs, addr) - s.log.Verbo("Sending a GetAccepted to %s", toIPDesc(addr)) + if peer, exists := s.conns.GetPeerID(validatorID); exists { + peers = append(peers, peer) + s.log.Verbo("Sending a GetAccepted to %s", vID) } else { s.log.Debug("Attempted to send a GetAccepted message to a disconnected validator: %s", vID) s.executor.Add(func() { s.router.GetAcceptedFailed(vID, chainID, requestID) }) @@ -199,8 +197,8 @@ func (s *Voting) GetAccepted(validatorIDs ids.ShortSet, chainID ids.ID, requestI build := Builder{} msg, err := build.GetAccepted(chainID, requestID, containerIDs) if err != nil { - for _, addr := range addrs { - if validatorID, exists := s.conns.GetID(addr); exists { + for _, peer := range peers { + if validatorID, exists := s.conns.GetID(peer); exists { s.executor.Add(func() { s.router.GetAcceptedFailed(validatorID, chainID, requestID) }) } } @@ -213,18 +211,18 @@ func (s *Voting) GetAccepted(validatorIDs ids.ShortSet, chainID ids.ID, requestI "\nChain: %s"+ "\nRequest ID: %d"+ "\nContainer IDs:%s", - len(addrs), + len(peers), chainID, requestID, containerIDs, ) - s.send(msg, addrs...) - s.numGetAcceptedSent.Add(float64(len(addrs))) + s.send(msg, peers...) + s.numGetAcceptedSent.Add(float64(len(peers))) } // Accepted implements the Sender interface. func (s *Voting) Accepted(validatorID ids.ShortID, chainID ids.ID, requestID uint32, containerIDs ids.Set) { - addr, exists := s.conns.GetIP(validatorID) + peer, exists := s.conns.GetPeerID(validatorID) if !exists { s.log.Debug("Attempted to send an Accepted message to a disconnected validator: %s", validatorID) return // Validator is not connected @@ -239,23 +237,21 @@ func (s *Voting) Accepted(validatorID ids.ShortID, chainID ids.ID, requestID uin s.log.Verbo("Sending an Accepted message."+ "\nValidator: %s"+ - "\nDestination: %s"+ "\nChain: %s"+ "\nRequest ID: %d"+ "\nContainer IDs: %s", validatorID, - toIPDesc(addr), chainID, requestID, containerIDs, ) - s.send(msg, addr) + s.send(msg, peer) s.numAcceptedSent.Inc() } // Get implements the Sender interface. func (s *Voting) Get(validatorID ids.ShortID, chainID ids.ID, requestID uint32, containerID ids.ID) { - addr, exists := s.conns.GetIP(validatorID) + peer, exists := s.conns.GetPeerID(validatorID) if !exists { s.log.Debug("Attempted to send a Get message to a disconnected validator: %s", validatorID) s.executor.Add(func() { s.router.GetFailed(validatorID, chainID, requestID, containerID) }) @@ -268,23 +264,21 @@ func (s *Voting) Get(validatorID ids.ShortID, chainID ids.ID, requestID uint32, s.log.Verbo("Sending a Get message."+ "\nValidator: %s"+ - "\nDestination: %s"+ "\nChain: %s"+ "\nRequest ID: %d"+ "\nContainer ID: %s", validatorID, - toIPDesc(addr), chainID, requestID, containerID, ) - s.send(msg, addr) + s.send(msg, peer) s.numGetSent.Inc() } // Put implements the Sender interface. func (s *Voting) Put(validatorID ids.ShortID, chainID ids.ID, requestID uint32, containerID ids.ID, container []byte) { - addr, exists := s.conns.GetIP(validatorID) + peer, exists := s.conns.GetPeerID(validatorID) if !exists { s.log.Debug("Attempted to send a Container message to a disconnected validator: %s", validatorID) return // Validator is not connected @@ -299,31 +293,29 @@ func (s *Voting) Put(validatorID ids.ShortID, chainID ids.ID, requestID uint32, s.log.Verbo("Sending a Container message."+ "\nValidator: %s"+ - "\nDestination: %s"+ "\nChain: %s"+ "\nRequest ID: %d"+ "\nContainer ID: %s"+ "\nContainer:\n%s", validatorID, - toIPDesc(addr), chainID, requestID, containerID, formatting.DumpBytes{Bytes: container}, ) - s.send(msg, addr) + s.send(msg, peer) s.numPutSent.Inc() } // PushQuery implements the Sender interface. func (s *Voting) PushQuery(validatorIDs ids.ShortSet, chainID ids.ID, requestID uint32, containerID ids.ID, container []byte) { - addrs := []salticidae.NetAddr(nil) + peers := []salticidae.PeerID(nil) validatorIDList := validatorIDs.List() for _, validatorID := range validatorIDList { vID := validatorID - if addr, exists := s.conns.GetIP(vID); exists { - addrs = append(addrs, addr) - s.log.Verbo("Sending a PushQuery to %s", toIPDesc(addr)) + if peer, exists := s.conns.GetPeerID(vID); exists { + peers = append(peers, peer) + s.log.Verbo("Sending a PushQuery to %s", vID) } else { s.log.Debug("Attempted to send a PushQuery message to a disconnected validator: %s", vID) s.executor.Add(func() { s.router.QueryFailed(vID, chainID, requestID) }) @@ -333,8 +325,8 @@ func (s *Voting) PushQuery(validatorIDs ids.ShortSet, chainID ids.ID, requestID build := Builder{} msg, err := build.PushQuery(chainID, requestID, containerID, container) if err != nil { - for _, addr := range addrs { - if validatorID, exists := s.conns.GetID(addr); exists { + for _, peer := range peers { + if validatorID, exists := s.conns.GetID(peer); exists { s.executor.Add(func() { s.router.QueryFailed(validatorID, chainID, requestID) }) } } @@ -348,25 +340,25 @@ func (s *Voting) PushQuery(validatorIDs ids.ShortSet, chainID ids.ID, requestID "\nRequest ID: %d"+ "\nContainer ID: %s"+ "\nContainer:\n%s", - len(addrs), + len(peers), chainID, requestID, containerID, formatting.DumpBytes{Bytes: container}, ) - s.send(msg, addrs...) - s.numPushQuerySent.Add(float64(len(addrs))) + s.send(msg, peers...) + s.numPushQuerySent.Add(float64(len(peers))) } // PullQuery implements the Sender interface. func (s *Voting) PullQuery(validatorIDs ids.ShortSet, chainID ids.ID, requestID uint32, containerID ids.ID) { - addrs := []salticidae.NetAddr(nil) + peers := []salticidae.PeerID(nil) validatorIDList := validatorIDs.List() for _, validatorID := range validatorIDList { vID := validatorID - if addr, exists := s.conns.GetIP(vID); exists { - addrs = append(addrs, addr) - s.log.Verbo("Sending a PullQuery to %s", toIPDesc(addr)) + if peer, exists := s.conns.GetPeerID(vID); exists { + peers = append(peers, peer) + s.log.Verbo("Sending a PullQuery to %s", vID) } else { s.log.Warn("Attempted to send a PullQuery message to a disconnected validator: %s", vID) s.executor.Add(func() { s.router.QueryFailed(vID, chainID, requestID) }) @@ -382,18 +374,18 @@ func (s *Voting) PullQuery(validatorIDs ids.ShortSet, chainID ids.ID, requestID "\nChain: %s"+ "\nRequest ID: %d"+ "\nContainer ID: %s", - len(addrs), + len(peers), chainID, requestID, containerID, ) - s.send(msg, addrs...) - s.numPullQuerySent.Add(float64(len(addrs))) + s.send(msg, peers...) + s.numPullQuerySent.Add(float64(len(peers))) } // Chits implements the Sender interface. func (s *Voting) Chits(validatorID ids.ShortID, chainID ids.ID, requestID uint32, votes ids.Set) { - addr, exists := s.conns.GetIP(validatorID) + peer, exists := s.conns.GetPeerID(validatorID) if !exists { s.log.Debug("Attempted to send a Chits message to a disconnected validator: %s", validatorID) return // Validator is not connected @@ -408,21 +400,19 @@ func (s *Voting) Chits(validatorID ids.ShortID, chainID ids.ID, requestID uint32 s.log.Verbo("Sending a Chits message."+ "\nValidator: %s"+ - "\nDestination: %s"+ "\nChain: %s"+ "\nRequest ID: %d"+ "\nNumber of Chits: %d", validatorID, - toIPDesc(addr), chainID, requestID, votes.Len(), ) - s.send(msg, addr) + s.send(msg, peer) s.numChitsSent.Inc() } -func (s *Voting) send(msg Msg, addrs ...salticidae.NetAddr) { +func (s *Voting) send(msg Msg, peers ...salticidae.PeerID) { ds := msg.DataStream() defer ds.Free() ba := salticidae.NewByteArrayMovedFromDataStream(ds, false) @@ -430,12 +420,12 @@ func (s *Voting) send(msg Msg, addrs ...salticidae.NetAddr) { cMsg := salticidae.NewMsgMovedFromByteArray(msg.Op(), ba, false) defer cMsg.Free() - switch len(addrs) { + switch len(peers) { case 0: case 1: - s.net.SendMsg(cMsg, addrs[0]) + s.net.SendMsg(cMsg, peers[0]) default: - s.net.MulticastMsgByMove(cMsg, addrs) + s.net.MulticastMsgByMove(cMsg, peers) } } @@ -620,18 +610,16 @@ func chits(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe.Poi func (s *Voting) sanitize(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, op salticidae.Opcode) (ids.ShortID, ids.ID, uint32, Msg, error) { conn := salticidae.PeerNetworkConnFromC(salticidae.CPeerNetworkConn((*C.peernetwork_conn_t)(_conn))) - addr := conn.GetPeerAddr(false) - defer addr.Free() - if addr.IsNull() { - return ids.ShortID{}, ids.ID{}, 0, nil, errConnectionDropped - } - s.log.Verbo("Receiving message from %s", toIPDesc(addr)) + peer := conn.GetPeerID(false) + defer peer.Free() - validatorID, exists := s.conns.GetID(addr) + validatorID, exists := s.conns.GetID(peer) if !exists { - return ids.ShortID{}, ids.ID{}, 0, nil, fmt.Errorf("message received from an un-registered source: %s", toIPDesc(addr)) + return ids.ShortID{}, ids.ID{}, 0, nil, fmt.Errorf("message received from an un-registered peer") } + s.log.Verbo("Receiving message from %s", validatorID) + msg := salticidae.MsgFromC(salticidae.CMsg(_msg)) codec := Codec{} pMsg, err := codec.Parse(op, msg.GetPayloadByMove()) diff --git a/node/node.go b/node/node.go index ed82378..e6fbbf2 100644 --- a/node/node.go +++ b/node/node.go @@ -275,11 +275,12 @@ func (n *Node) StartConsensusServer() error { // Add bootstrap nodes to the peer network for _, peer := range n.Config.BootstrapPeers { if !peer.IP.Equal(n.Config.StakingIP) { - bootstrapIP := salticidae.NewNetAddrFromIPPortString(peer.IP.String(), true, &err) - if code := err.GetCode(); code != 0 { - return fmt.Errorf("failed to create bootstrap ip addr: %s", salticidae.StrError(code)) - } - n.PeerNet.AddPeer(bootstrapIP) + // TODO: Add the bootstrap IP + // bootstrapIP := salticidae.NewNetAddrFromIPPortString(peer.IP.String(), true, &err) + // if code := err.GetCode(); code != 0 { + // return fmt.Errorf("failed to create bootstrap ip addr: %s", salticidae.StrError(code)) + // } + // n.PeerNet.AddPeer(bootstrapIP) } else { n.Log.Error("can't add self as a bootstrapper") } diff --git a/utils/ip.go b/utils/ip.go index 1b35fa7..658cca7 100644 --- a/utils/ip.go +++ b/utils/ip.go @@ -10,6 +10,28 @@ import ( "strconv" ) +// This was taken from: https://stackoverflow.com/a/50825191/3478466 +var privateIPBlocks []*net.IPNet + +func init() { + for _, cidr := range []string{ + "127.0.0.0/8", // IPv4 loopback + "10.0.0.0/8", // RFC1918 + "172.16.0.0/12", // RFC1918 + "192.168.0.0/16", // RFC1918 + "169.254.0.0/16", // RFC3927 link-local + "::1/128", // IPv6 loopback + "fe80::/10", // IPv6 link-local + "fc00::/7", // IPv6 unique local addr + } { + _, block, err := net.ParseCIDR(cidr) + if err != nil { + panic(fmt.Errorf("parse error on %q: %v", cidr, err)) + } + privateIPBlocks = append(privateIPBlocks, block) + } +} + var ( errBadIP = errors.New("bad ip format") ) @@ -35,6 +57,26 @@ func (ipDesc IPDesc) String() string { return net.JoinHostPort(ipDesc.IP.String(), fmt.Sprintf("%d", ipDesc.Port)) } +// IsPrivate attempts to decide if the ip address in this descriptor is a local +// ip address. +// This function was taken from: https://stackoverflow.com/a/50825191/3478466 +func (ipDesc IPDesc) IsPrivate() bool { + ip := ipDesc.IP + if ip.IsLoopback() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() { + return true + } + + for _, block := range privateIPBlocks { + if block.Contains(ip) { + return true + } + } + // added so that default ips will be marked as private + return len(ip) == 0 || + ip.Equal(net.IPv4zero) || + ip.Equal(net.IPv6zero) +} + // ToIPDesc ... func ToIPDesc(str string) (IPDesc, error) { host, portStr, err := net.SplitHostPort(str) From c6b92425efe7c9677284c216c881c3425e0ac86c Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Sat, 18 Apr 2020 21:02:40 -0400 Subject: [PATCH 24/61] Added connections --- networking/connections.go | 16 ++++++++++++++-- networking/handshake_handlers.go | 24 +++++++++++++----------- node/node.go | 13 +++++++------ 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/networking/connections.go b/networking/connections.go index 7b6a6ea..6226e01 100644 --- a/networking/connections.go +++ b/networking/connections.go @@ -246,8 +246,20 @@ func (c *connections) conns() ([]salticidae.PeerID, []ids.ShortID, []utils.IPDes func (c *connections) len() int { return len(c.idToPeerID) } func toID(peer salticidae.PeerID) [32]byte { - // TODO: need to get the hash from the peer - return [32]byte{} + ds := salticidae.NewDataStream(false) + + peerInt := peer.AsUInt256() + peerInt.Serialize(ds) + + size := ds.Size() + dsb := ds.GetDataInPlace(size) + idBytes := dsb.Get() + + id := [32]byte{} + copy(id[:], idBytes) + + ds.Free() + return id } func toIPDesc(addr salticidae.NetAddr) utils.IPDesc { diff --git a/networking/handshake_handlers.go b/networking/handshake_handlers.go index f602162..39b10a7 100644 --- a/networking/handshake_handlers.go +++ b/networking/handshake_handlers.go @@ -4,7 +4,7 @@ package networking // #include "salticidae/network.h" -// bool checkPeerCertificate(msgnetwork_conn_t *, bool, void *); +// bool connHandler(msgnetwork_conn_t *, bool, void *); // void unknownPeerHandler(netaddr_t *, x509_t *, void *); // void peerHandler(peernetwork_conn_t *, bool, void *); // void ping(msg_t *, msgnetwork_conn_t *, void *); @@ -143,7 +143,7 @@ func (nm *Handshake) Initialize( net := peerNet.AsMsgNetwork() - net.RegConnHandler(salticidae.MsgNetworkConnCallback(C.checkPeerCertificate), nil) + net.RegConnHandler(salticidae.MsgNetworkConnCallback(C.connHandler), nil) peerNet.RegPeerHandler(salticidae.PeerNetworkPeerCallback(C.peerHandler), nil) peerNet.RegUnknownPeerHandler(salticidae.PeerNetworkUnknownPeerCallback(C.unknownPeerHandler), nil) net.RegHandler(Ping, salticidae.MsgNetworkMsgCallback(C.ping), nil) @@ -303,9 +303,10 @@ func (nm *Handshake) send(msg Msg, peers ...salticidae.PeerID) { } } -// checkPeerCertificate of a new inbound connection -//export checkPeerCertificate -func checkPeerCertificate(_ *C.struct_msgnetwork_conn_t, connected C.bool, _ unsafe.Pointer) C.bool { +// connHandler notifies of a new inbound connection +//export connHandler +func connHandler(_ *C.struct_msgnetwork_conn_t, connected C.bool, _ unsafe.Pointer) C.bool { + HandshakeNet.log.Error("connHandler called") return connected } @@ -381,6 +382,8 @@ func (nm *Handshake) disconnectedFromPeer(peer salticidae.PeerID, addr salticida // connected is false if a formerly connected peer has disconnected //export peerHandler func peerHandler(_conn *C.struct_peernetwork_conn_t, connected C.bool, _ unsafe.Pointer) { + HandshakeNet.log.Error("peerHandler called") + pConn := salticidae.PeerNetworkConnFromC(salticidae.CPeerNetworkConn(_conn)) addr := pConn.GetPeerAddr(true) peer := pConn.GetPeerID(true) @@ -395,6 +398,8 @@ func peerHandler(_conn *C.struct_peernetwork_conn_t, connected C.bool, _ unsafe. // unknownPeerHandler notifies of an unknown peer connection attempt //export unknownPeerHandler func unknownPeerHandler(_addr *C.netaddr_t, _cert *C.x509_t, _ unsafe.Pointer) { + HandshakeNet.log.Error("unknownPeerHandler called") + addr := salticidae.NetAddrFromC(salticidae.CNetAddr(_addr)).Copy(true) ip := toIPDesc(addr) @@ -555,6 +560,8 @@ func peerList(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe. return } + msgNet := HandshakeNet.net.AsMsgNetwork() + ips := pMsg.Get(Peers).([]utils.IPDesc) cErr := salticidae.NewError() for _, ip := range ips { @@ -565,12 +572,7 @@ func peerList(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe. if !HandshakeNet.pending.ContainsIP(ip) && !HandshakeNet.connections.ContainsIP(ip) { HandshakeNet.log.Debug("Adding peer %s", ip) - // TODO: Attempt to connect to the IP - // ipCert := toShortID(ip) - // HandshakeNet.reconnectTimeout.Put(ipCert.LongID(), func() { - // HandshakeNet.net.DelPeer(addr) - // }) - // HandshakeNet.net.AddPeer(addr) + msgNet.Connect(addr) } } } diff --git a/node/node.go b/node/node.go index e6fbbf2..8331f61 100644 --- a/node/node.go +++ b/node/node.go @@ -272,15 +272,16 @@ func (n *Node) StartConsensusServer() error { } } + msgNet := n.PeerNet.AsMsgNetwork() + // Add bootstrap nodes to the peer network for _, peer := range n.Config.BootstrapPeers { if !peer.IP.Equal(n.Config.StakingIP) { - // TODO: Add the bootstrap IP - // bootstrapIP := salticidae.NewNetAddrFromIPPortString(peer.IP.String(), true, &err) - // if code := err.GetCode(); code != 0 { - // return fmt.Errorf("failed to create bootstrap ip addr: %s", salticidae.StrError(code)) - // } - // n.PeerNet.AddPeer(bootstrapIP) + bootstrapIP := salticidae.NewNetAddrFromIPPortString(peer.IP.String(), true, &err) + if code := err.GetCode(); code != 0 { + return fmt.Errorf("failed to create bootstrap ip addr: %s", salticidae.StrError(code)) + } + msgNet.Connect(bootstrapIP) } else { n.Log.Error("can't add self as a bootstrapper") } From aa60e61c5c1e8c86745c0fa0ef8d2a6f8d8d8af2 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Sat, 18 Apr 2020 22:47:53 -0400 Subject: [PATCH 25/61] 1-way handshake on a staking network --- main/main.go | 4 ++ main/params.go | 8 +-- networking/handshake_handlers.go | 109 ++++++++++++++++++++++--------- node/node.go | 7 +- utils/ip.go | 10 ++- 5 files changed, 95 insertions(+), 43 deletions(-) diff --git a/main/main.go b/main/main.go index fc7ae99..1fab9ef 100644 --- a/main/main.go +++ b/main/main.go @@ -40,6 +40,10 @@ func main() { defer log.StopOnPanic() defer Config.DB.Close() + if Config.StakingIP.IsZero() { + log.Warn("NAT traversal has failed. If this node becomes a staker, it may lose its reward due to being unreachable.") + } + // Track if sybil control is enforced if !Config.EnableStaking { log.Warn("Staking and p2p encryption are disabled. Packet spoofing is possible.") diff --git a/main/params.go b/main/params.go index 0438a60..f5155a0 100644 --- a/main/params.go +++ b/main/params.go @@ -157,11 +157,9 @@ func init() { // If public IP is not specified, get it using shell command dig if *consensusIP == "" { ip, err = Config.Nat.IP() - errs.Add(fmt.Errorf( - "%s\n"+ - "If you are trying to create a local network, try adding --public-ip=127.0.0.1\n"+ - "If you are attempting to connect to a public network, you may need to manually report your IP and perform port forwarding", - err)) + if err != nil { + ip = net.IPv4zero + } } else { ip = net.ParseIP(*consensusIP) } diff --git a/networking/handshake_handlers.go b/networking/handshake_handlers.go index 39b10a7..bfa15ee 100644 --- a/networking/handshake_handlers.go +++ b/networking/handshake_handlers.go @@ -115,6 +115,8 @@ type Handshake struct { awaitingLock sync.Mutex awaiting []*networking.AwaitingConnections + + requestedConnections map[string]struct{} } // Initialize to the c networking library. This should only be done once during @@ -141,6 +143,8 @@ func (nm *Handshake) Initialize( nm.pending = NewConnections() nm.connections = NewConnections() + nm.requestedConnections = make(map[string]struct{}) + net := peerNet.AsMsgNetwork() net.RegConnHandler(salticidae.MsgNetworkConnCallback(C.connHandler), nil) @@ -165,6 +169,23 @@ func (nm *Handshake) Initialize( go nm.log.RecoverAndPanic(nm.peerListGossiper.Dispatch) } +// Connect ... +func (nm *Handshake) Connect(addr salticidae.NetAddr) { + if !nm.enableStaking { + peer := salticidae.NewPeerIDFromNetAddr(addr, false) + nm.net.AddPeer(peer) + nm.net.SetPeerAddr(peer, addr) + nm.net.ConnPeer(peer, 600, 1) + peer.Free() + } else { + ip := toIPDesc(addr) + nm.requestedConnections[ip.String()] = struct{}{} + + msgNet := nm.net.AsMsgNetwork() + msgNet.Connect(addr) + } +} + // AwaitConnections ... func (nm *Handshake) AwaitConnections(awaiting *networking.AwaitingConnections) { nm.awaitingLock.Lock() @@ -264,7 +285,7 @@ func (nm *Handshake) SendPeerList(peers ...salticidae.PeerID) error { ipsToSend := []utils.IPDesc(nil) for i, id := range ids { ip := ips[i] - if !ip.IsPrivate() && nm.vdrs.Contains(id) { + if !ip.IsZero() && nm.vdrs.Contains(id) { ipsToSend = append(ipsToSend, ip) } } @@ -305,28 +326,51 @@ func (nm *Handshake) send(msg Msg, peers ...salticidae.PeerID) { // connHandler notifies of a new inbound connection //export connHandler -func connHandler(_ *C.struct_msgnetwork_conn_t, connected C.bool, _ unsafe.Pointer) C.bool { - HandshakeNet.log.Error("connHandler called") - return connected +func connHandler(_conn *C.struct_msgnetwork_conn_t, connected C.bool, _ unsafe.Pointer) C.bool { + if !HandshakeNet.enableStaking || !bool(connected) { + return connected + } + + conn := salticidae.MsgNetworkConnFromC(salticidae.CMsgNetworkConn(_conn)) + addr := conn.GetAddr() + ip := toIPDesc(addr) + + ipStr := ip.String() + if _, exists := HandshakeNet.requestedConnections[ipStr]; !exists { + HandshakeNet.log.Debug("connHandler called with %s", ip) + return true + } + delete(HandshakeNet.requestedConnections, ipStr) + + cert := conn.GetPeerCert() + peer := salticidae.NewPeerIDFromX509(cert, false) + + HandshakeNet.net.AddPeer(peer) + HandshakeNet.net.SetPeerAddr(peer, addr) + HandshakeNet.net.ConnPeer(peer, 600, 1) + + peer.Free() + return true } -func (nm *Handshake) connectedToPeer(conn *C.struct_peernetwork_conn_t, peer salticidae.PeerID, addr salticidae.NetAddr) { - ip := toIPDesc(addr) +func (nm *Handshake) connectedToPeer(conn *C.struct_peernetwork_conn_t, peer salticidae.PeerID) { + peerBytes := toID(peer) + peerID := ids.NewID(peerBytes) + // If we're enforcing staking, use a peer's certificate to uniquely identify them // Otherwise, use a hash of their ip to identify them cert := ids.ShortID{} - ipCert := toShortID(ip) if nm.enableStaking { cert = getPeerCert(conn) } else { - cert = ipCert + key := [20]byte{} + copy(key[:], peerID.Bytes()) + cert = ids.NewShortID(key) } - nm.log.Debug("Connected to %s", ip) + nm.log.Debug("Connected to %s", cert) - longCert := cert.LongID() - nm.reconnectTimeout.Remove(longCert) - nm.reconnectTimeout.Remove(ipCert.LongID()) + nm.reconnectTimeout.Remove(peerID) nm.pending.Add(peer, cert, utils.IPDesc{}) @@ -334,13 +378,13 @@ func (nm *Handshake) connectedToPeer(conn *C.struct_peernetwork_conn_t, peer sal *handler = func() { if nm.pending.ContainsPeerID(peer) { nm.SendGetVersion(peer) - nm.versionTimeout.Put(longCert, *handler) + nm.versionTimeout.Put(peerID, *handler) } } (*handler)() } -func (nm *Handshake) disconnectedFromPeer(peer salticidae.PeerID, addr salticidae.NetAddr) { +func (nm *Handshake) disconnectedFromPeer(peer salticidae.PeerID) { cert := ids.ShortID{} if pendingCert, exists := nm.pending.GetID(peer); exists { cert = pendingCert @@ -350,17 +394,19 @@ func (nm *Handshake) disconnectedFromPeer(peer salticidae.PeerID, addr salticida return } - nm.log.Info("Disconnected from %s", toIPDesc(addr)) + nm.log.Info("Disconnected from %s", cert) + + peerBytes := toID(peer) + peerID := ids.NewID(peerBytes) - longCert := cert.LongID() if nm.vdrs.Contains(cert) { - nm.reconnectTimeout.Put(longCert, func() { + nm.reconnectTimeout.Put(peerID, func() { nm.net.DelPeer(peer) }) } else { nm.net.DelPeer(peer) } - nm.versionTimeout.Remove(longCert) + nm.versionTimeout.Remove(peerID) if !nm.enableStaking { nm.vdrs.Remove(cert) @@ -382,23 +428,22 @@ func (nm *Handshake) disconnectedFromPeer(peer salticidae.PeerID, addr salticida // connected is false if a formerly connected peer has disconnected //export peerHandler func peerHandler(_conn *C.struct_peernetwork_conn_t, connected C.bool, _ unsafe.Pointer) { - HandshakeNet.log.Error("peerHandler called") + HandshakeNet.log.Debug("peerHandler called") pConn := salticidae.PeerNetworkConnFromC(salticidae.CPeerNetworkConn(_conn)) - addr := pConn.GetPeerAddr(true) peer := pConn.GetPeerID(true) if connected { - HandshakeNet.connectedToPeer(_conn, peer, addr) + HandshakeNet.connectedToPeer(_conn, peer) } else { - HandshakeNet.disconnectedFromPeer(peer, addr) + HandshakeNet.disconnectedFromPeer(peer) } } // unknownPeerHandler notifies of an unknown peer connection attempt //export unknownPeerHandler func unknownPeerHandler(_addr *C.netaddr_t, _cert *C.x509_t, _ unsafe.Pointer) { - HandshakeNet.log.Error("unknownPeerHandler called") + HandshakeNet.log.Debug("unknownPeerHandler called") addr := salticidae.NetAddrFromC(salticidae.CNetAddr(_addr)).Copy(true) ip := toIPDesc(addr) @@ -406,17 +451,17 @@ func unknownPeerHandler(_addr *C.netaddr_t, _cert *C.x509_t, _ unsafe.Pointer) { HandshakeNet.log.Info("Adding peer %s", ip) var peer salticidae.PeerID - id := ids.ShortID{} if HandshakeNet.enableStaking { cert := salticidae.X509FromC(salticidae.CX509(_cert)) - id = getCert(cert) peer = salticidae.NewPeerIDFromX509(cert, true) } else { - id = toShortID(ip) peer = salticidae.NewPeerIDFromNetAddr(addr, true) } - HandshakeNet.reconnectTimeout.Put(id.LongID(), func() { + peerBytes := toID(peer) + peerID := ids.NewID(peerBytes) + + HandshakeNet.reconnectTimeout.Put(peerID, func() { HandshakeNet.net.DelPeer(peer) }) HandshakeNet.net.AddPeer(peer) @@ -506,7 +551,10 @@ func version(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe.P HandshakeNet.SendPeerList(peer) HandshakeNet.connections.Add(peer, id, ip) - HandshakeNet.versionTimeout.Remove(id.LongID()) + peerBytes := toID(peer) + peerID := ids.NewID(peerBytes) + + HandshakeNet.versionTimeout.Remove(peerID) if !HandshakeNet.enableStaking { HandshakeNet.vdrs.Add(validators.NewValidator(id, 1)) @@ -560,19 +608,16 @@ func peerList(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe. return } - msgNet := HandshakeNet.net.AsMsgNetwork() - ips := pMsg.Get(Peers).([]utils.IPDesc) cErr := salticidae.NewError() for _, ip := range ips { - HandshakeNet.log.Verbo("Trying to adding peer %s", ip) addr := salticidae.NewNetAddrFromIPPortString(ip.String(), true, &cErr) if cErr.GetCode() == 0 && !HandshakeNet.myAddr.IsEq(addr) { // Make sure not to connect to myself ip := toIPDesc(addr) if !HandshakeNet.pending.ContainsIP(ip) && !HandshakeNet.connections.ContainsIP(ip) { HandshakeNet.log.Debug("Adding peer %s", ip) - msgNet.Connect(addr) + HandshakeNet.Connect(addr) } } } diff --git a/node/node.go b/node/node.go index 8331f61..42d334d 100644 --- a/node/node.go +++ b/node/node.go @@ -272,16 +272,15 @@ func (n *Node) StartConsensusServer() error { } } - msgNet := n.PeerNet.AsMsgNetwork() - // Add bootstrap nodes to the peer network for _, peer := range n.Config.BootstrapPeers { if !peer.IP.Equal(n.Config.StakingIP) { - bootstrapIP := salticidae.NewNetAddrFromIPPortString(peer.IP.String(), true, &err) + bootstrapAddr := salticidae.NewNetAddrFromIPPortString(peer.IP.String(), true, &err) if code := err.GetCode(); code != 0 { return fmt.Errorf("failed to create bootstrap ip addr: %s", salticidae.StrError(code)) } - msgNet.Connect(bootstrapIP) + + n.ValidatorAPI.Connect(bootstrapAddr) } else { n.Log.Error("can't add self as a bootstrapper") } diff --git a/utils/ip.go b/utils/ip.go index 658cca7..f5f84db 100644 --- a/utils/ip.go +++ b/utils/ip.go @@ -71,8 +71,14 @@ func (ipDesc IPDesc) IsPrivate() bool { return true } } - // added so that default ips will be marked as private - return len(ip) == 0 || + return true +} + +// IsZero returns if the IP or port is zeroed out +func (ipDesc IPDesc) IsZero() bool { + ip := ipDesc.IP + return ipDesc.Port == 0 || + len(ip) == 0 || ip.Equal(net.IPv4zero) || ip.Equal(net.IPv6zero) } From 50fde3841c10648b0bf228fdc5adb10ebf66df9b Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Sat, 18 Apr 2020 23:45:18 -0400 Subject: [PATCH 26/61] update ami --- scripts/aws/create.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/scripts/aws/create.py b/scripts/aws/create.py index 07d75e7..6558c11 100755 --- a/scripts/aws/create.py +++ b/scripts/aws/create.py @@ -6,14 +6,14 @@ Start a number of AVA nodes on Amazon EC2 import boto3 -bootstapNode = "Borealis-Bootstrap" -fullNode = "Borealis-Node" +bootstapNode = "Cascade-Bootstrap" +fullNode = "Cascade-Node" def runInstances(ec2, num: int, name: str): if num > 0: ec2.run_instances( - ImageId="ami-0badd1c10cb7673e9", + ImageId="ami-0c088c21fbcdb8a48", InstanceType="c5.large", MaxCount=num, MinCount=num, @@ -29,11 +29,9 @@ def runInstances(ec2, num: int, name: str): def main(): import argparse - parser = argparse.ArgumentParser( - description=__doc__, - ) - parser.add_argument('numBootstraps', type=int) - parser.add_argument('numNodes', type=int) + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("numBootstraps", type=int) + parser.add_argument("numNodes", type=int) args = parser.parse_args() ec2 = boto3.client("ec2") From f3f55108b9bf60021e641816ec1f6bb4fdf8edd7 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 19 Apr 2020 18:08:08 -0400 Subject: [PATCH 27/61] use salticidae-go v0.1.0 --- scripts/env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/env.sh b/scripts/env.sh index 24141f9..7dd549b 100644 --- a/scripts/env.sh +++ b/scripts/env.sh @@ -9,5 +9,5 @@ SALTICIDAE_GO_HOME="$GOPATH/src/github.com/ava-labs/salticidae-go/" if [[ -f "$SALTICIDAE_GO_HOME/salticidae/libsalticidae.a" ]]; then source "$SALTICIDAE_GO_HOME/scripts/env.sh" else - source /dev/stdin <<<"$(curl -sS https://raw.githubusercontent.com/ava-labs/salticidae-go/master/setup.sh)" + source /dev/stdin <<<"$(curl -sS https://raw.githubusercontent.com/ava-labs/salticidae-go/v0.1.0/setup.sh)" fi From a1e10c73321e15ffd505fb8c056a67a1333b8b4b Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Sun, 19 Apr 2020 18:19:05 -0400 Subject: [PATCH 28/61] Change coreth dependency to use tag --- scripts/build.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/build.sh b/scripts/build.sh index b2d1984..cef2d78 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -17,6 +17,9 @@ if [[ -d "$CORETH_PATH/.git" ]]; then else go get -t -v -d "$CORETH_PKG/..." fi +cd "$CORETH_PATH" +git branch tags/v0.1.0 +cd - GECKO_PKG=github.com/ava-labs/gecko GECKO_PATH="$GOPATH/src/$GECKO_PKG" From 765bffecda46a02ae46288a6a81408321b68b2be Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 19 Apr 2020 18:24:32 -0400 Subject: [PATCH 29/61] use `checkout` --- scripts/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build.sh b/scripts/build.sh index cef2d78..7000d3f 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -18,7 +18,7 @@ else go get -t -v -d "$CORETH_PKG/..." fi cd "$CORETH_PATH" -git branch tags/v0.1.0 +git -c advice.detachedHead=false checkout v0.1.0 cd - GECKO_PKG=github.com/ava-labs/gecko From b7305f78b6185b4f46cd69dac93e42f324542a4b Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Mon, 20 Apr 2020 10:40:39 -0400 Subject: [PATCH 30/61] Properly remove the IP when removing the connection --- networking/connections.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/networking/connections.go b/networking/connections.go index 6226e01..239d814 100644 --- a/networking/connections.go +++ b/networking/connections.go @@ -187,15 +187,18 @@ func (c *connections) getID(peer salticidae.PeerID) (ids.ShortID, bool) { } func (c *connections) remove(peer salticidae.PeerID, id ids.ShortID) { - c.removePeerID(peer) c.removeID(id) + c.removePeerID(peer) } func (c *connections) removePeerID(peer salticidae.PeerID) { peerID := toID(peer) if id, exists := c.peerIDToID[peerID]; exists { + idKey := id.Key() + delete(c.peerIDToID, peerID) - delete(c.idToPeerID, id.Key()) + delete(c.idToPeerID, idKey) + delete(c.idToIP, idKey) } } @@ -204,6 +207,7 @@ func (c *connections) removeID(id ids.ShortID) { if peer, exists := c.idToPeerID[idKey]; exists { delete(c.peerIDToID, toID(peer)) delete(c.idToPeerID, idKey) + delete(c.idToIP, idKey) } } From b4f3bb6719664f4246caa253269cec0738512013 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Mon, 20 Apr 2020 10:42:16 -0400 Subject: [PATCH 31/61] reduce diff --- networking/connections.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/networking/connections.go b/networking/connections.go index 239d814..4eaaaf7 100644 --- a/networking/connections.go +++ b/networking/connections.go @@ -187,8 +187,8 @@ func (c *connections) getID(peer salticidae.PeerID) (ids.ShortID, bool) { } func (c *connections) remove(peer salticidae.PeerID, id ids.ShortID) { - c.removeID(id) c.removePeerID(peer) + c.removeID(id) } func (c *connections) removePeerID(peer salticidae.PeerID) { From 6bcedf1d64e2cac5bb8e6d267b2b33a54b0f2ce4 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Mon, 20 Apr 2020 20:00:36 -0400 Subject: [PATCH 32/61] wip --- networking/handshake_handlers.go | 140 +++++++++++++++----------- node/node.go | 6 +- scripts/ansible/inventory.yml | 33 +++--- scripts/ansible/ping_playbook.yml | 11 ++ scripts/ansible/restart_playbook.yml | 2 +- scripts/ansible/update_playbook.yml | 4 +- snow/engine/avalanche/bootstrapper.go | 1 + snow/engine/avalanche/voter.go | 19 +++- 8 files changed, 132 insertions(+), 84 deletions(-) create mode 100755 scripts/ansible/ping_playbook.yml diff --git a/networking/handshake_handlers.go b/networking/handshake_handlers.go index bfa15ee..94ac481 100644 --- a/networking/handshake_handlers.go +++ b/networking/handshake_handlers.go @@ -74,6 +74,10 @@ const ( // PeerListStakerGossipFraction calculates the fraction of stakers that are // gossiped to. If set to 1, then only stakers will be gossiped to. PeerListStakerGossipFraction = 2 + + // ConnectTimeout is the amount of time to wait before attempt to connect to + // an unknown peer + ConnectTimeout = time.Second // GetVersionTimeout is the amount of time to wait before sending a // getVersion message to a partially connected peer GetVersionTimeout = 2 * time.Second @@ -96,27 +100,37 @@ var ( type Handshake struct { handshakeMetrics - networkID uint32 + networkID uint32 // ID of the network I'm running, used to prevent connecting to the wrong network log logging.Logger - vdrs validators.Set - myAddr salticidae.NetAddr - myID ids.ShortID - net salticidae.PeerNetwork - enableStaking bool // Should only be false for local tests + vdrs validators.Set // set of current validators in the AVAnet + myAddr salticidae.NetAddr // IP I communicate to peers + myID ids.ShortID // ID that identifies myself as a staker or not + net salticidae.PeerNetwork // C messaging network + enableStaking bool // Should only be false for local tests - clock timer.Clock - pending Connections // Connections that I haven't gotten version messages from - connections Connections // Connections that I think are connected + clock timer.Clock - versionTimeout timer.TimeoutManager + // Connections that I have added by IP, but haven't gotten an ID from + requestedLock sync.Mutex + requested map[string]struct{} + requestedTimeout timer.TimeoutManager + + // Connections that I have added as a peer, but haven't gotten a version + // message from + pending Connections + versionTimeout timer.TimeoutManager + + // Connections that I have gotten a valid version message from + connections Connections reconnectTimeout timer.TimeoutManager + + // IPs of nodes I'm connected to will be repeatedly gossiped throughout the network peerListGossiper *timer.Repeater + // If any chain is blocked on connecting to peers, track these blockers here awaitingLock sync.Mutex awaiting []*networking.AwaitingConnections - - requestedConnections map[string]struct{} } // Initialize to the c networking library. This should only be done once during @@ -132,19 +146,34 @@ func (nm *Handshake) Initialize( networkID uint32, ) { log.AssertTrue(nm.net == nil, "Should only register network handlers once") + + nm.handshakeMetrics.Initialize(log, registerer) + + nm.networkID = networkID + nm.log = log nm.vdrs = vdrs nm.myAddr = myAddr nm.myID = myID nm.net = peerNet nm.enableStaking = enableStaking - nm.networkID = networkID + + nm.requested = make(map[string]struct{}) + nm.requestedTimeout.Initialize(ConnectTimeout) + go nm.log.RecoverAndPanic(nm.requestedTimeout.Dispatch) nm.pending = NewConnections() + nm.versionTimeout.Initialize(GetVersionTimeout) + go nm.log.RecoverAndPanic(nm.versionTimeout.Dispatch) + nm.connections = NewConnections() + nm.reconnectTimeout.Initialize(ReconnectTimeout) + go nm.log.RecoverAndPanic(nm.reconnectTimeout.Dispatch) - nm.requestedConnections = make(map[string]struct{}) + nm.peerListGossiper = timer.NewRepeater(nm.gossipPeerList, PeerListGossipSpacing) + go nm.log.RecoverAndPanic(nm.peerListGossiper.Dispatch) + // register c message callbacks net := peerNet.AsMsgNetwork() net.RegConnHandler(salticidae.MsgNetworkConnCallback(C.connHandler), nil) @@ -156,30 +185,41 @@ func (nm *Handshake) Initialize( net.RegHandler(Version, salticidae.MsgNetworkMsgCallback(C.version), nil) net.RegHandler(GetPeerList, salticidae.MsgNetworkMsgCallback(C.getPeerList), nil) net.RegHandler(PeerList, salticidae.MsgNetworkMsgCallback(C.peerList), nil) +} - nm.handshakeMetrics.Initialize(nm.log, registerer) +// ConnectTo add the peer as a connection and connects to them. Will free peer +func (nm *Handshake) ConnectTo(peer salticidae.PeerID, addr salticidae.NetAddr) { + if !nm.pending.ContainsPeerID(peer) && !nm.connections.ContainsPeerID(peer) { + HandshakeNet.net.AddPeer(peer) + HandshakeNet.net.SetPeerAddr(peer, addr) + HandshakeNet.net.ConnPeer(peer, 600, 1) - nm.versionTimeout.Initialize(GetVersionTimeout) - go nm.log.RecoverAndPanic(nm.versionTimeout.Dispatch) + // TODO: Should add the peer to the pending set, register a timeout to + // remove the peer + } - nm.reconnectTimeout.Initialize(ReconnectTimeout) - go nm.log.RecoverAndPanic(nm.reconnectTimeout.Dispatch) - - nm.peerListGossiper = timer.NewRepeater(nm.gossipPeerList, PeerListGossipSpacing) - go nm.log.RecoverAndPanic(nm.peerListGossiper.Dispatch) + peer.Free() } // Connect ... func (nm *Handshake) Connect(addr salticidae.NetAddr) { + ip := toIPDesc(addr) + ipStr := ip.String() + if nm.pending.ContainsIP(ip) || nm.connections.ContainsIP(ip) { + return + } + + nm.log.Debug("Adding peer %s", ip) + + //TODO: + if !nm.enableStaking { peer := salticidae.NewPeerIDFromNetAddr(addr, false) - nm.net.AddPeer(peer) - nm.net.SetPeerAddr(peer, addr) - nm.net.ConnPeer(peer, 600, 1) - peer.Free() + nm.ConnectTo(peer, addr) } else { - ip := toIPDesc(addr) - nm.requestedConnections[ip.String()] = struct{}{} + nm.requestedConnections[ipStr] = struct{}{} + + nm.log.Verbo("Attempting to discover peer at %s", ipStr) msgNet := nm.net.AsMsgNetwork() msgNet.Connect(addr) @@ -344,12 +384,7 @@ func connHandler(_conn *C.struct_msgnetwork_conn_t, connected C.bool, _ unsafe.P cert := conn.GetPeerCert() peer := salticidae.NewPeerIDFromX509(cert, false) - - HandshakeNet.net.AddPeer(peer) - HandshakeNet.net.SetPeerAddr(peer, addr) - HandshakeNet.net.ConnPeer(peer, 600, 1) - - peer.Free() + HandshakeNet.ConnectTo(peer, addr) return true } @@ -388,14 +423,14 @@ func (nm *Handshake) disconnectedFromPeer(peer salticidae.PeerID) { cert := ids.ShortID{} if pendingCert, exists := nm.pending.GetID(peer); exists { cert = pendingCert + nm.log.Info("Disconnected from pending peer %s", cert) } else if connectedCert, exists := nm.connections.GetID(peer); exists { cert = connectedCert + nm.log.Info("Disconnected from peer %s", cert) } else { return } - nm.log.Info("Disconnected from %s", cert) - peerBytes := toID(peer) peerID := ids.NewID(peerBytes) @@ -612,20 +647,14 @@ func peerList(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe. cErr := salticidae.NewError() for _, ip := range ips { addr := salticidae.NewNetAddrFromIPPortString(ip.String(), true, &cErr) - if cErr.GetCode() == 0 && !HandshakeNet.myAddr.IsEq(addr) { // Make sure not to connect to myself - ip := toIPDesc(addr) - if !HandshakeNet.pending.ContainsIP(ip) && !HandshakeNet.connections.ContainsIP(ip) { - HandshakeNet.log.Debug("Adding peer %s", ip) - HandshakeNet.Connect(addr) - } + if cErr.GetCode() != 0 || HandshakeNet.myAddr.IsEq(addr) { + // Make sure not to connect to myself + continue } - } -} -func getMsgCert(_conn *C.struct_msgnetwork_conn_t) ids.ShortID { - conn := salticidae.MsgNetworkConnFromC(salticidae.CMsgNetworkConn(_conn)) - return getCert(conn.GetPeerCert()) + HandshakeNet.Connect(addr) + } } func getPeerCert(_conn *C.struct_peernetwork_conn_t) ids.ShortID { @@ -635,13 +664,12 @@ func getPeerCert(_conn *C.struct_peernetwork_conn_t) ids.ShortID { func getCert(cert salticidae.X509) ids.ShortID { der := cert.GetDer(false) - defer der.Free() - certDS := salticidae.NewDataStreamMovedFromByteArray(der, false) - defer certDS.Free() - certBytes := certDS.GetDataInPlace(certDS.Size()).Get() certID, err := ids.ToShortID(hashing.PubkeyBytesToAddress(certBytes)) + + certDS.Free() + der.Free() HandshakeNet.log.AssertNoError(err) return certID } @@ -651,13 +679,3 @@ func checkCompatibility(myVersion string, peerVersion string) bool { // At the moment, we are all compatible. return true } - -func toAddr(ip utils.IPDesc, autoFree bool) salticidae.NetAddr { - err := salticidae.NewError() - addr := salticidae.NewNetAddrFromIPPortString(ip.String(), autoFree, &err) - HandshakeNet.log.AssertTrue(err.GetCode() == 0, "IP Failed parsing") - return addr -} -func toShortID(ip utils.IPDesc) ids.ShortID { - return ids.NewShortID(hashing.ComputeHash160Array([]byte(ip.String()))) -} diff --git a/node/node.go b/node/node.go index 42d334d..2cc7eaa 100644 --- a/node/node.go +++ b/node/node.go @@ -5,7 +5,7 @@ package node // #include "salticidae/network.h" // void onTerm(int sig, void *); -// void errorHandler(SalticidaeCError *, bool, void *); +// void errorHandler(SalticidaeCError *, bool, int32_t, void *); import "C" import ( @@ -130,14 +130,14 @@ func onTerm(C.int, unsafe.Pointer) { } //export errorHandler -func errorHandler(_err *C.struct_SalticidaeCError, fatal C.bool, _ unsafe.Pointer) { +func errorHandler(_err *C.struct_SalticidaeCError, fatal C.bool, asyncID C.int32_t, _ unsafe.Pointer) { err := (*salticidae.Error)(unsafe.Pointer(_err)) if fatal { MainNode.Log.Fatal("Error during async call: %s", salticidae.StrError(err.GetCode())) MainNode.EC.Stop() return } - MainNode.Log.Error("Error during async call: %s", salticidae.StrError(err.GetCode())) + MainNode.Log.Error("Error during async with ID %d call: %s", asyncID, salticidae.StrError(err.GetCode())) } func (n *Node) initNetlib() error { diff --git a/scripts/ansible/inventory.yml b/scripts/ansible/inventory.yml index 5315082..1da8bad 100755 --- a/scripts/ansible/inventory.yml +++ b/scripts/ansible/inventory.yml @@ -1,15 +1,14 @@ borealis_bootstrap: hosts: bootstrap1: - ansible_host: 3.227.207.132 - http_tls_enabled: true - http_tls_key_file: "/home/ubuntu/ssl/privkey.pem" - http_tls_cert_file: "/home/ubuntu/ssl/fullchain.pem" + ansible_host: 3.84.129.247 + staking_tls_key_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker1.key" + staking_tls_cert_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker1.crt" vars: ansible_connection: ssh ansible_user: ubuntu - network_id: "cascade" + network_id: "local" api_admin_enabled: true api_keystore_enabled: true api_metrics_enabled: true @@ -29,7 +28,7 @@ borealis_bootstrap: staking_tls_key_file: "/home/ubuntu/keys/staker.key" staking_tls_cert_file: "/home/ubuntu/keys/staker.crt" log_dir: "/home/ubuntu/.gecko" - log_level: debug + log_level: verbo snow_sample_size: 3 snow_quorum_size: 2 snow_virtuous_commit_threshold: 20 @@ -43,18 +42,26 @@ borealis_bootstrap: borealis_node: hosts: node1: - ansible_host: 34.207.133.167 + ansible_host: 35.153.99.244 + staking_tls_key_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker2.key" + staking_tls_cert_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker2.crt" node2: - ansible_host: 107.23.241.199 + ansible_host: 34.201.137.119 + staking_tls_key_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker3.key" + staking_tls_cert_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker3.crt" node3: - ansible_host: 54.197.215.186 + ansible_host: 54.146.1.110 + staking_tls_key_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker4.key" + staking_tls_cert_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker4.crt" node4: - ansible_host: 18.234.153.22 + ansible_host: 54.91.255.231 + staking_tls_key_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker5.key" + staking_tls_cert_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker5.crt" vars: ansible_connection: ssh ansible_user: ubuntu - network_id: "cascade" + network_id: "local" api_admin_enabled: true api_keystore_enabled: true api_metrics_enabled: true @@ -67,8 +74,8 @@ borealis_node: http_tls_enabled: false http_tls_key_file: "" http_tls_cert_file: "" - bootstrap_ips: "3.227.207.132:21001" - bootstrap_ids: "NX4zVkuiRJZYe6Nzzav7GXN3TakUet3Co" + bootstrap_ips: "3.84.129.247:21001" + bootstrap_ids: "7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg" staking_port: 21001 staking_tls_enabled: true staking_tls_key_file: "/home/ubuntu/keys/staker.key" diff --git a/scripts/ansible/ping_playbook.yml b/scripts/ansible/ping_playbook.yml new file mode 100755 index 0000000..0c47625 --- /dev/null +++ b/scripts/ansible/ping_playbook.yml @@ -0,0 +1,11 @@ + +--- +- name: Update the network + connection: ssh + gather_facts: false + hosts: all + tasks: + - name: Ping node + shell: "ls" + environment: + PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin diff --git a/scripts/ansible/restart_playbook.yml b/scripts/ansible/restart_playbook.yml index 48d44fb..f888d5d 100755 --- a/scripts/ansible/restart_playbook.yml +++ b/scripts/ansible/restart_playbook.yml @@ -8,7 +8,7 @@ ava_binary: ~/go/src/github.com/ava-labs/gecko/build/ava repo_folder: ~/go/src/github.com/ava-labs/gecko repo_name: ava-labs/gecko - repo_branch: cascade + repo_branch: master tasks: - name: Kill Node command: killall ava diff --git a/scripts/ansible/update_playbook.yml b/scripts/ansible/update_playbook.yml index b28def3..9147886 100755 --- a/scripts/ansible/update_playbook.yml +++ b/scripts/ansible/update_playbook.yml @@ -8,7 +8,7 @@ ava_binary: ~/go/src/github.com/ava-labs/gecko/build/ava repo_folder: ~/go/src/github.com/ava-labs/gecko repo_name: ava-labs/gecko - repo_branch: cascade + repo_branch: master tasks: - name: Kill Node command: killall ava @@ -25,6 +25,6 @@ environment: PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin - name: Start node - shell: "nohup {{ ava_binary }} --network-id={{ network_id }} --api-admin-enabled={{ api_admin_enabled }} --api-keystore-enabled={{ api_keystore_enabled }} --api-metrics-enabled={{ api_metrics_enabled }} --ava-tx-fee={{ ava_tx_fee }} --assertions-enabled={{ assertions_enabled }} --signature-verification-enabled={{ signature_verification_enabled }} --db-enabled={{ db_enabled }} --db-dir={{ db_dir }} --http-port={{ http_port }} --http-tls-enabled={{ http_tls_enabled }} --http-tls-key-file={{ http_tls_key_file }} --http-tls-cert-file={{ http_tls_cert_file }} --bootstrap-ips={{ bootstrap_ips }} --bootstrap-ids={{ bootstrap_ids }} --public-ip={{ ansible_host }} --staking-port={{ staking_port }} --staking-tls-enabled={{ staking_tls_enabled }} --staking-tls-key-file={{ staking_tls_key_file }} --staking-tls-cert-file={{ staking_tls_cert_file }} --log-dir={{ log_dir }} --log-level={{ log_level }} --snow-sample-size={{ snow_sample_size }} --snow-quorum-size={{ snow_quorum_size }} --snow-virtuous-commit-threshold={{ snow_virtuous_commit_threshold }} --snow-rogue-commit-threshold={{ snow_rogue_commit_threshold }} --snow-avalanche-num-parents={{ snow_avalanche_num_parents }} --snow-avalanche-batch-size={{ snow_avalanche_batch_size }} --api-ipcs-enabled={{ api_ipcs_enabled }} --xput-server-enabled={{ xput_server_enabled }} --xput-server-port={{ xput_server_port }} >/dev/null 2>&1 &" + shell: "nohup {{ ava_binary }} --network-id={{ network_id }} --api-admin-enabled={{ api_admin_enabled }} --api-keystore-enabled={{ api_keystore_enabled }} --api-metrics-enabled={{ api_metrics_enabled }} --ava-tx-fee={{ ava_tx_fee }} --assertions-enabled={{ assertions_enabled }} --signature-verification-enabled={{ signature_verification_enabled }} --db-enabled={{ db_enabled }} --db-dir={{ db_dir }} --http-port={{ http_port }} --http-tls-enabled={{ http_tls_enabled }} --http-tls-key-file={{ http_tls_key_file }} --http-tls-cert-file={{ http_tls_cert_file }} --bootstrap-ips={{ bootstrap_ips }} --bootstrap-ids={{ bootstrap_ids }} --public-ip={{ ansible_host }} --staking-port={{ staking_port }} --staking-tls-enabled={{ staking_tls_enabled }} --staking-tls-key-file={{ staking_tls_key_file }} --staking-tls-cert-file={{ staking_tls_cert_file }} --log-dir={{ log_dir }} --log-level={{ log_level }} --snow-sample-size={{ snow_sample_size }} --snow-quorum-size={{ snow_quorum_size }} --snow-virtuous-commit-threshold={{ snow_virtuous_commit_threshold }} --snow-rogue-commit-threshold={{ snow_rogue_commit_threshold }} --snow-avalanche-num-parents={{ snow_avalanche_num_parents }} --snow-avalanche-batch-size={{ snow_avalanche_batch_size }} --api-ipcs-enabled={{ api_ipcs_enabled }} --xput-server-enabled={{ xput_server_enabled }} --xput-server-port={{ xput_server_port }} >~/all-logs.txt 2>&1 &" environment: PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin diff --git a/snow/engine/avalanche/bootstrapper.go b/snow/engine/avalanche/bootstrapper.go index 0f58194..7bacd46 100644 --- a/snow/engine/avalanche/bootstrapper.go +++ b/snow/engine/avalanche/bootstrapper.go @@ -207,6 +207,7 @@ func (b *bootstrapper) finish() { func (b *bootstrapper) executeAll(jobs *queue.Jobs, numBlocked prometheus.Gauge) { for job, err := jobs.Pop(); err == nil; job, err = jobs.Pop() { numBlocked.Dec() + b.BootstrapConfig.Context.Log.Debug("Executing: %s", job.ID()) if err := jobs.Execute(job); err != nil { b.BootstrapConfig.Context.Log.Warn("Error executing: %s", err) } diff --git a/snow/engine/avalanche/voter.go b/snow/engine/avalanche/voter.go index 7430495..90b7b2f 100644 --- a/snow/engine/avalanche/voter.go +++ b/snow/engine/avalanche/voter.go @@ -79,12 +79,23 @@ func (v *voter) bubbleVotes(votes ids.UniqueBag) ids.UniqueBag { vtx := vts[0] vts = vts[1:] - if status := vtx.Status(); status.Fetched() && !v.t.Consensus.VertexIssued(vtx) { - vts = append(vts, vtx.Parents()...) - } else if !status.Decided() && v.t.Consensus.VertexIssued(vtx) { + status := vtx.Status() + if !status.Fetched() { + v.t.Config.Context.Log.Debug("Dropping %d vote(s) for %s because the vertex is unknown", set.Len(), vtx.ID()) + continue + } + + if status.Decided() { + v.t.Config.Context.Log.Debug("Dropping %d vote(s) for %s because the vertex is accepted", set.Len(), vtx.ID()) + continue + } + + if v.t.Consensus.VertexIssued(vtx) { + v.t.Config.Context.Log.Debug("Applying %d vote(s) for %s", set.Len(), vtx.ID()) bubbledVotes.UnionSet(vtx.ID(), set) } else { - v.t.Config.Context.Log.Debug("Dropping %d vote(s) for %s because the vertex is invalid", set.Len(), vtx.ID()) + v.t.Config.Context.Log.Debug("Bubbling %d vote(s) for %s because the vertex isn't issued", set.Len(), vtx.ID()) + vts = append(vts, vtx.Parents()...) } } } From 3c9187fc7b4c2353bdc334bfaab0f83460ccf7df Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Mon, 20 Apr 2020 20:25:22 -0400 Subject: [PATCH 33/61] wip --- networking/handshake_handlers.go | 59 +++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/networking/handshake_handlers.go b/networking/handshake_handlers.go index 94ac481..4ba44cc 100644 --- a/networking/handshake_handlers.go +++ b/networking/handshake_handlers.go @@ -187,18 +187,26 @@ func (nm *Handshake) Initialize( net.RegHandler(PeerList, salticidae.MsgNetworkMsgCallback(C.peerList), nil) } -// ConnectTo add the peer as a connection and connects to them. Will free peer -func (nm *Handshake) ConnectTo(peer salticidae.PeerID, addr salticidae.NetAddr) { - if !nm.pending.ContainsPeerID(peer) && !nm.connections.ContainsPeerID(peer) { - HandshakeNet.net.AddPeer(peer) - HandshakeNet.net.SetPeerAddr(peer, addr) - HandshakeNet.net.ConnPeer(peer, 600, 1) - - // TODO: Should add the peer to the pending set, register a timeout to - // remove the peer +// ConnectTo add the peer as a connection and connects to them. +func (nm *Handshake) ConnectTo(peer salticidae.PeerID, stakerID ids.ShortID, addr salticidae.NetAddr) { + if nm.pending.ContainsPeerID(peer) || nm.connections.ContainsPeerID(peer) { + return } - peer.Free() + nm.net.AddPeer(peer) + nm.net.SetPeerAddr(peer, addr) + nm.net.ConnPeer(peer, 600, 1) + + ip := toIPDesc(addr) + nm.pending.Add(peer, stakerID, ip) + + peerBytes := toID(peer) + peerID := ids.NewID(peerBytes) + + nm.reconnectTimeout.Put(peerID, func() { + nm.pending.Remove(peer, stakerID) + nm.net.DelPeer(peer) + }) } // Connect ... @@ -211,19 +219,37 @@ func (nm *Handshake) Connect(addr salticidae.NetAddr) { nm.log.Debug("Adding peer %s", ip) - //TODO: - if !nm.enableStaking { - peer := salticidae.NewPeerIDFromNetAddr(addr, false) + peer := salticidae.NewPeerIDFromNetAddr(addr, true) nm.ConnectTo(peer, addr) - } else { - nm.requestedConnections[ipStr] = struct{}{} + return + } + + count := new(int) + *count = 600 + handler := new(func()) + *handler = func() { + nm.requestedLock.Lock() + defer nm.requestedLock.Unlock() + + if *count <= 0 { + delete(nm.requested, ipStr) + return + } + *count-- + + if nm.pending.ContainsIP(ip) || nm.connections.ContainsIP(ip) { + return + } nm.log.Verbo("Attempting to discover peer at %s", ipStr) + nm.requested[ipStr] = struct{}{} + msgNet := nm.net.AsMsgNetwork() msgNet.Connect(addr) } + (*handler)() } // AwaitConnections ... @@ -383,7 +409,8 @@ func connHandler(_conn *C.struct_msgnetwork_conn_t, connected C.bool, _ unsafe.P delete(HandshakeNet.requestedConnections, ipStr) cert := conn.GetPeerCert() - peer := salticidae.NewPeerIDFromX509(cert, false) + peer := salticidae.NewPeerIDFromX509(cert, true) + HandshakeNet.ConnectTo(peer, addr) return true } From 2c76dd19544670504b56e05b06ea0288ce6bf56d Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Mon, 20 Apr 2020 22:33:33 -0400 Subject: [PATCH 34/61] wip --- networking/handshake_handlers.go | 90 ++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 28 deletions(-) diff --git a/networking/handshake_handlers.go b/networking/handshake_handlers.go index 4ba44cc..daa0aff 100644 --- a/networking/handshake_handlers.go +++ b/networking/handshake_handlers.go @@ -114,16 +114,16 @@ type Handshake struct { // Connections that I have added by IP, but haven't gotten an ID from requestedLock sync.Mutex requested map[string]struct{} - requestedTimeout timer.TimeoutManager + requestedTimeout timer.TimeoutManager // keys are hashes of the ip:port string // Connections that I have added as a peer, but haven't gotten a version // message from pending Connections - versionTimeout timer.TimeoutManager + versionTimeout timer.TimeoutManager // keys are the peer IDs // Connections that I have gotten a valid version message from connections Connections - reconnectTimeout timer.TimeoutManager + reconnectTimeout timer.TimeoutManager // keys are the peer IDs // IPs of nodes I'm connected to will be repeatedly gossiped throughout the network peerListGossiper *timer.Repeater @@ -193,6 +193,8 @@ func (nm *Handshake) ConnectTo(peer salticidae.PeerID, stakerID ids.ShortID, add return } + nm.log.Info("Attempting to connect to %s", stakerID) + nm.net.AddPeer(peer) nm.net.SetPeerAddr(peer, addr) nm.net.ConnPeer(peer, 600, 1) @@ -205,7 +207,10 @@ func (nm *Handshake) ConnectTo(peer salticidae.PeerID, stakerID ids.ShortID, add nm.reconnectTimeout.Put(peerID, func() { nm.pending.Remove(peer, stakerID) + nm.connections.Remove(peer, stakerID) nm.net.DelPeer(peer) + + nm.numPeers.Set(float64(nm.connections.Len())) }) } @@ -217,11 +222,11 @@ func (nm *Handshake) Connect(addr salticidae.NetAddr) { return } - nm.log.Debug("Adding peer %s", ip) + nm.log.Info("Adding peer %s", ip) if !nm.enableStaking { peer := salticidae.NewPeerIDFromNetAddr(addr, true) - nm.ConnectTo(peer, addr) + nm.ConnectTo(peer, toShortID(ip), addr) return } @@ -232,6 +237,14 @@ func (nm *Handshake) Connect(addr salticidae.NetAddr) { nm.requestedLock.Lock() defer nm.requestedLock.Unlock() + if *count == 600 { + nm.requested[ipStr] = struct{}{} + } + + if _, exists := nm.requested[ipStr]; !exists { + return + } + if *count <= 0 { delete(nm.requested, ipStr) return @@ -242,12 +255,13 @@ func (nm *Handshake) Connect(addr salticidae.NetAddr) { return } - nm.log.Verbo("Attempting to discover peer at %s", ipStr) - - nm.requested[ipStr] = struct{}{} + nm.log.Info("Attempting to discover peer at %s", ipStr) msgNet := nm.net.AsMsgNetwork() msgNet.Connect(addr) + + ipID := ids.NewID(hashing.ComputeHash256Array([]byte(ipStr))) + nm.requestedTimeout.Put(ipID, *handler) } (*handler)() } @@ -397,21 +411,27 @@ func connHandler(_conn *C.struct_msgnetwork_conn_t, connected C.bool, _ unsafe.P return connected } + HandshakeNet.requestedLock.Lock() + defer HandshakeNet.requestedLock.Unlock() + conn := salticidae.MsgNetworkConnFromC(salticidae.CMsgNetworkConn(_conn)) addr := conn.GetAddr() ip := toIPDesc(addr) - ipStr := ip.String() - if _, exists := HandshakeNet.requestedConnections[ipStr]; !exists { + + ipID := ids.NewID(hashing.ComputeHash256Array([]byte(ipStr))) + HandshakeNet.requestedTimeout.Remove(ipID) + + if _, exists := HandshakeNet.requested[ipStr]; !exists { HandshakeNet.log.Debug("connHandler called with %s", ip) return true } - delete(HandshakeNet.requestedConnections, ipStr) + delete(HandshakeNet.requested, ipStr) cert := conn.GetPeerCert() peer := salticidae.NewPeerIDFromX509(cert, true) - HandshakeNet.ConnectTo(peer, addr) + HandshakeNet.ConnectTo(peer, getCert(cert), addr) return true } @@ -434,8 +454,6 @@ func (nm *Handshake) connectedToPeer(conn *C.struct_peernetwork_conn_t, peer sal nm.reconnectTimeout.Remove(peerID) - nm.pending.Add(peer, cert, utils.IPDesc{}) - handler := new(func()) *handler = func() { if nm.pending.ContainsPeerID(peer) { @@ -461,23 +479,28 @@ func (nm *Handshake) disconnectedFromPeer(peer salticidae.PeerID) { peerBytes := toID(peer) peerID := ids.NewID(peerBytes) + nm.versionTimeout.Remove(peerID) + nm.connections.Remove(peer, cert) + nm.numPeers.Set(float64(nm.connections.Len())) + if nm.vdrs.Contains(cert) { nm.reconnectTimeout.Put(peerID, func() { + nm.pending.Remove(peer, cert) + nm.connections.Remove(peer, cert) nm.net.DelPeer(peer) + + nm.numPeers.Set(float64(nm.connections.Len())) }) + nm.pending.Add(peer, cert, utils.IPDesc{}) } else { + nm.pending.Remove(peer, cert) nm.net.DelPeer(peer) } - nm.versionTimeout.Remove(peerID) if !nm.enableStaking { nm.vdrs.Remove(cert) } - nm.pending.RemovePeerID(peer) - nm.connections.RemovePeerID(peer) - nm.numPeers.Set(float64(nm.connections.Len())) - nm.awaitingLock.Lock() defer nm.awaitingLock.Unlock() for _, awaiting := range HandshakeNet.awaiting { @@ -513,19 +536,27 @@ func unknownPeerHandler(_addr *C.netaddr_t, _cert *C.x509_t, _ unsafe.Pointer) { HandshakeNet.log.Info("Adding peer %s", ip) var peer salticidae.PeerID + var id ids.ShortID if HandshakeNet.enableStaking { cert := salticidae.X509FromC(salticidae.CX509(_cert)) peer = salticidae.NewPeerIDFromX509(cert, true) + id = getCert(cert) } else { peer = salticidae.NewPeerIDFromNetAddr(addr, true) + id = toShortID(ip) } peerBytes := toID(peer) peerID := ids.NewID(peerBytes) HandshakeNet.reconnectTimeout.Put(peerID, func() { + HandshakeNet.pending.Remove(peer, id) + HandshakeNet.connections.Remove(peer, id) HandshakeNet.net.DelPeer(peer) + + HandshakeNet.numPeers.Set(float64(HandshakeNet.connections.Len())) }) + HandshakeNet.pending.Add(peer, id, utils.IPDesc{}) HandshakeNet.net.AddPeer(peer) } @@ -568,12 +599,17 @@ func version(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe.P conn := salticidae.PeerNetworkConnFromC(salticidae.CPeerNetworkConn(_conn)) peer := conn.GetPeerID(true) + peerBytes := toID(peer) + peerID := ids.NewID(peerBytes) + + HandshakeNet.versionTimeout.Remove(peerID) + id, exists := HandshakeNet.pending.GetID(peer) if !exists { + HandshakeNet.log.Warn("Dropping Version message because the peer isn't pending") return } - - defer HandshakeNet.pending.Remove(peer, id) + HandshakeNet.pending.Remove(peer, id) build := Builder{} pMsg, err := build.Parse(Version, msg.GetPayloadByMove()) @@ -612,18 +648,12 @@ func version(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe.P HandshakeNet.SendPeerList(peer) HandshakeNet.connections.Add(peer, id, ip) - - peerBytes := toID(peer) - peerID := ids.NewID(peerBytes) - - HandshakeNet.versionTimeout.Remove(peerID) + HandshakeNet.numPeers.Set(float64(HandshakeNet.connections.Len())) if !HandshakeNet.enableStaking { HandshakeNet.vdrs.Add(validators.NewValidator(id, 1)) } - HandshakeNet.numPeers.Set(float64(HandshakeNet.connections.Len())) - HandshakeNet.awaitingLock.Lock() defer HandshakeNet.awaitingLock.Unlock() @@ -706,3 +736,7 @@ func checkCompatibility(myVersion string, peerVersion string) bool { // At the moment, we are all compatible. return true } + +func toShortID(ip utils.IPDesc) ids.ShortID { + return ids.NewShortID(hashing.ComputeHash160Array([]byte(ip.String()))) +} From 386ef6b0008cc37630a496ac2e27d8f24882db78 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Tue, 21 Apr 2020 01:31:10 -0400 Subject: [PATCH 35/61] cleaned up logging in avalanche bubbling --- snow/engine/avalanche/voter.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/snow/engine/avalanche/voter.go b/snow/engine/avalanche/voter.go index 90b7b2f..6e52a34 100644 --- a/snow/engine/avalanche/voter.go +++ b/snow/engine/avalanche/voter.go @@ -81,20 +81,20 @@ func (v *voter) bubbleVotes(votes ids.UniqueBag) ids.UniqueBag { status := vtx.Status() if !status.Fetched() { - v.t.Config.Context.Log.Debug("Dropping %d vote(s) for %s because the vertex is unknown", set.Len(), vtx.ID()) + v.t.Config.Context.Log.Verbo("Dropping %d vote(s) for %s because the vertex is unknown", set.Len(), vtx.ID()) continue } if status.Decided() { - v.t.Config.Context.Log.Debug("Dropping %d vote(s) for %s because the vertex is accepted", set.Len(), vtx.ID()) + v.t.Config.Context.Log.Verbo("Dropping %d vote(s) for %s because the vertex is decided", set.Len(), vtx.ID()) continue } if v.t.Consensus.VertexIssued(vtx) { - v.t.Config.Context.Log.Debug("Applying %d vote(s) for %s", set.Len(), vtx.ID()) + v.t.Config.Context.Log.Verbo("Applying %d vote(s) for %s", set.Len(), vtx.ID()) bubbledVotes.UnionSet(vtx.ID(), set) } else { - v.t.Config.Context.Log.Debug("Bubbling %d vote(s) for %s because the vertex isn't issued", set.Len(), vtx.ID()) + v.t.Config.Context.Log.Verbo("Bubbling %d vote(s) for %s because the vertex isn't issued", set.Len(), vtx.ID()) vts = append(vts, vtx.Parents()...) } } From 14f178612eff57589577957a15c763d42d7bf8ce Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Tue, 21 Apr 2020 01:57:10 -0400 Subject: [PATCH 36/61] added plugin dir flag --- scripts/ansible/inventory.yml | 2 ++ scripts/ansible/restart_playbook.yml | 6 +++--- scripts/ansible/update_playbook.yml | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/ansible/inventory.yml b/scripts/ansible/inventory.yml index 1da8bad..0964550 100755 --- a/scripts/ansible/inventory.yml +++ b/scripts/ansible/inventory.yml @@ -27,6 +27,7 @@ borealis_bootstrap: staking_tls_enabled: true staking_tls_key_file: "/home/ubuntu/keys/staker.key" staking_tls_cert_file: "/home/ubuntu/keys/staker.crt" + plugin_dir: "/home/ubuntu/go/src/github.com/ava-labs/gecko/build/plugins" log_dir: "/home/ubuntu/.gecko" log_level: verbo snow_sample_size: 3 @@ -80,6 +81,7 @@ borealis_node: staking_tls_enabled: true staking_tls_key_file: "/home/ubuntu/keys/staker.key" staking_tls_cert_file: "/home/ubuntu/keys/staker.crt" + plugin_dir: "/home/ubuntu/go/src/github.com/ava-labs/gecko/build/plugins" log_dir: "/home/ubuntu/.gecko" log_level: debug snow_sample_size: 3 diff --git a/scripts/ansible/restart_playbook.yml b/scripts/ansible/restart_playbook.yml index f888d5d..deec014 100755 --- a/scripts/ansible/restart_playbook.yml +++ b/scripts/ansible/restart_playbook.yml @@ -7,8 +7,8 @@ vars: ava_binary: ~/go/src/github.com/ava-labs/gecko/build/ava repo_folder: ~/go/src/github.com/ava-labs/gecko - repo_name: ava-labs/gecko - repo_branch: master + repo_name: ava-labs/gecko-internal + repo_branch: retry-connections tasks: - name: Kill Node command: killall ava @@ -33,6 +33,6 @@ path: "{{ log_dir }}" state: absent - name: Start node - shell: "nohup {{ ava_binary }} --network-id={{ network_id }} --api-admin-enabled={{ api_admin_enabled }} --api-keystore-enabled={{ api_keystore_enabled }} --api-metrics-enabled={{ api_metrics_enabled }} --ava-tx-fee={{ ava_tx_fee }} --assertions-enabled={{ assertions_enabled }} --signature-verification-enabled={{ signature_verification_enabled }} --db-enabled={{ db_enabled }} --db-dir={{ db_dir }} --http-port={{ http_port }} --http-tls-enabled={{ http_tls_enabled }} --http-tls-key-file={{ http_tls_key_file }} --http-tls-cert-file={{ http_tls_cert_file }} --bootstrap-ips={{ bootstrap_ips }} --bootstrap-ids={{ bootstrap_ids }} --public-ip={{ ansible_host }} --staking-port={{ staking_port }} --staking-tls-enabled={{ staking_tls_enabled }} --staking-tls-key-file={{ staking_tls_key_file }} --staking-tls-cert-file={{ staking_tls_cert_file }} --log-dir={{ log_dir }} --log-level={{ log_level }} --snow-sample-size={{ snow_sample_size }} --snow-quorum-size={{ snow_quorum_size }} --snow-virtuous-commit-threshold={{ snow_virtuous_commit_threshold }} --snow-rogue-commit-threshold={{ snow_rogue_commit_threshold }} --snow-avalanche-num-parents={{ snow_avalanche_num_parents }} --snow-avalanche-batch-size={{ snow_avalanche_batch_size }} --api-ipcs-enabled={{ api_ipcs_enabled }} --xput-server-enabled={{ xput_server_enabled }} --xput-server-port={{ xput_server_port }} >/dev/null 2>&1 &" + shell: "nohup {{ ava_binary }} --network-id={{ network_id }} --api-admin-enabled={{ api_admin_enabled }} --api-keystore-enabled={{ api_keystore_enabled }} --api-metrics-enabled={{ api_metrics_enabled }} --ava-tx-fee={{ ava_tx_fee }} --assertions-enabled={{ assertions_enabled }} --signature-verification-enabled={{ signature_verification_enabled }} --db-enabled={{ db_enabled }} --db-dir={{ db_dir }} --http-port={{ http_port }} --http-tls-enabled={{ http_tls_enabled }} --http-tls-key-file={{ http_tls_key_file }} --http-tls-cert-file={{ http_tls_cert_file }} --bootstrap-ips={{ bootstrap_ips }} --bootstrap-ids={{ bootstrap_ids }} --public-ip={{ ansible_host }} --staking-port={{ staking_port }} --staking-tls-enabled={{ staking_tls_enabled }} --staking-tls-key-file={{ staking_tls_key_file }} --staking-tls-cert-file={{ staking_tls_cert_file }} --plugin-dir={{ plugin_dir }} --log-dir={{ log_dir }} --log-level={{ log_level }} --snow-sample-size={{ snow_sample_size }} --snow-quorum-size={{ snow_quorum_size }} --snow-virtuous-commit-threshold={{ snow_virtuous_commit_threshold }} --snow-rogue-commit-threshold={{ snow_rogue_commit_threshold }} --snow-avalanche-num-parents={{ snow_avalanche_num_parents }} --snow-avalanche-batch-size={{ snow_avalanche_batch_size }} --api-ipcs-enabled={{ api_ipcs_enabled }} --xput-server-enabled={{ xput_server_enabled }} --xput-server-port={{ xput_server_port }} >/dev/null 2>&1 &" environment: PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin diff --git a/scripts/ansible/update_playbook.yml b/scripts/ansible/update_playbook.yml index 9147886..478afec 100755 --- a/scripts/ansible/update_playbook.yml +++ b/scripts/ansible/update_playbook.yml @@ -7,8 +7,8 @@ vars: ava_binary: ~/go/src/github.com/ava-labs/gecko/build/ava repo_folder: ~/go/src/github.com/ava-labs/gecko - repo_name: ava-labs/gecko - repo_branch: master + repo_name: ava-labs/gecko-internal + repo_branch: retry-connections tasks: - name: Kill Node command: killall ava @@ -25,6 +25,6 @@ environment: PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin - name: Start node - shell: "nohup {{ ava_binary }} --network-id={{ network_id }} --api-admin-enabled={{ api_admin_enabled }} --api-keystore-enabled={{ api_keystore_enabled }} --api-metrics-enabled={{ api_metrics_enabled }} --ava-tx-fee={{ ava_tx_fee }} --assertions-enabled={{ assertions_enabled }} --signature-verification-enabled={{ signature_verification_enabled }} --db-enabled={{ db_enabled }} --db-dir={{ db_dir }} --http-port={{ http_port }} --http-tls-enabled={{ http_tls_enabled }} --http-tls-key-file={{ http_tls_key_file }} --http-tls-cert-file={{ http_tls_cert_file }} --bootstrap-ips={{ bootstrap_ips }} --bootstrap-ids={{ bootstrap_ids }} --public-ip={{ ansible_host }} --staking-port={{ staking_port }} --staking-tls-enabled={{ staking_tls_enabled }} --staking-tls-key-file={{ staking_tls_key_file }} --staking-tls-cert-file={{ staking_tls_cert_file }} --log-dir={{ log_dir }} --log-level={{ log_level }} --snow-sample-size={{ snow_sample_size }} --snow-quorum-size={{ snow_quorum_size }} --snow-virtuous-commit-threshold={{ snow_virtuous_commit_threshold }} --snow-rogue-commit-threshold={{ snow_rogue_commit_threshold }} --snow-avalanche-num-parents={{ snow_avalanche_num_parents }} --snow-avalanche-batch-size={{ snow_avalanche_batch_size }} --api-ipcs-enabled={{ api_ipcs_enabled }} --xput-server-enabled={{ xput_server_enabled }} --xput-server-port={{ xput_server_port }} >~/all-logs.txt 2>&1 &" + shell: "nohup {{ ava_binary }} --network-id={{ network_id }} --api-admin-enabled={{ api_admin_enabled }} --api-keystore-enabled={{ api_keystore_enabled }} --api-metrics-enabled={{ api_metrics_enabled }} --ava-tx-fee={{ ava_tx_fee }} --assertions-enabled={{ assertions_enabled }} --signature-verification-enabled={{ signature_verification_enabled }} --db-enabled={{ db_enabled }} --db-dir={{ db_dir }} --http-port={{ http_port }} --http-tls-enabled={{ http_tls_enabled }} --http-tls-key-file={{ http_tls_key_file }} --http-tls-cert-file={{ http_tls_cert_file }} --bootstrap-ips={{ bootstrap_ips }} --bootstrap-ids={{ bootstrap_ids }} --public-ip={{ ansible_host }} --staking-port={{ staking_port }} --staking-tls-enabled={{ staking_tls_enabled }} --staking-tls-key-file={{ staking_tls_key_file }} --staking-tls-cert-file={{ staking_tls_cert_file }} --plugin-dir={{ plugin_dir }} --log-dir={{ log_dir }} --log-level={{ log_level }} --snow-sample-size={{ snow_sample_size }} --snow-quorum-size={{ snow_quorum_size }} --snow-virtuous-commit-threshold={{ snow_virtuous_commit_threshold }} --snow-rogue-commit-threshold={{ snow_rogue_commit_threshold }} --snow-avalanche-num-parents={{ snow_avalanche_num_parents }} --snow-avalanche-batch-size={{ snow_avalanche_batch_size }} --api-ipcs-enabled={{ api_ipcs_enabled }} --xput-server-enabled={{ xput_server_enabled }} --xput-server-port={{ xput_server_port }} >~thelogs.txt 2>&1 &" environment: PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin From a3e3e5f21eefcee08223df14a309b8d5b92127f7 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Tue, 21 Apr 2020 13:55:01 -0400 Subject: [PATCH 37/61] changed ansible back to the testnet --- scripts/ansible/inventory.yml | 33 ++++++++++++----------------- scripts/ansible/update_playbook.yml | 2 +- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/scripts/ansible/inventory.yml b/scripts/ansible/inventory.yml index 0964550..a115a90 100755 --- a/scripts/ansible/inventory.yml +++ b/scripts/ansible/inventory.yml @@ -1,14 +1,15 @@ borealis_bootstrap: hosts: bootstrap1: - ansible_host: 3.84.129.247 - staking_tls_key_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker1.key" - staking_tls_cert_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker1.crt" + ansible_host: 3.227.207.132 + http_tls_enabled: true + http_tls_key_file: "/home/ubuntu/ssl/privkey.pem" + http_tls_cert_file: "/home/ubuntu/ssl/fullchain.pem" vars: ansible_connection: ssh ansible_user: ubuntu - network_id: "local" + network_id: "cascade" api_admin_enabled: true api_keystore_enabled: true api_metrics_enabled: true @@ -29,7 +30,7 @@ borealis_bootstrap: staking_tls_cert_file: "/home/ubuntu/keys/staker.crt" plugin_dir: "/home/ubuntu/go/src/github.com/ava-labs/gecko/build/plugins" log_dir: "/home/ubuntu/.gecko" - log_level: verbo + log_level: debug snow_sample_size: 3 snow_quorum_size: 2 snow_virtuous_commit_threshold: 20 @@ -43,26 +44,18 @@ borealis_bootstrap: borealis_node: hosts: node1: - ansible_host: 35.153.99.244 - staking_tls_key_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker2.key" - staking_tls_cert_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker2.crt" + ansible_host: 34.207.133.167 node2: - ansible_host: 34.201.137.119 - staking_tls_key_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker3.key" - staking_tls_cert_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker3.crt" + ansible_host: 107.23.241.199 node3: - ansible_host: 54.146.1.110 - staking_tls_key_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker4.key" - staking_tls_cert_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker4.crt" + ansible_host: 54.197.215.186 node4: - ansible_host: 54.91.255.231 - staking_tls_key_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker5.key" - staking_tls_cert_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker5.crt" + ansible_host: 18.234.153.22 vars: ansible_connection: ssh ansible_user: ubuntu - network_id: "local" + network_id: "cascade" api_admin_enabled: true api_keystore_enabled: true api_metrics_enabled: true @@ -75,8 +68,8 @@ borealis_node: http_tls_enabled: false http_tls_key_file: "" http_tls_cert_file: "" - bootstrap_ips: "3.84.129.247:21001" - bootstrap_ids: "7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg" + bootstrap_ips: "3.227.207.132:21001" + bootstrap_ids: "NX4zVkuiRJZYe6Nzzav7GXN3TakUet3Co" staking_port: 21001 staking_tls_enabled: true staking_tls_key_file: "/home/ubuntu/keys/staker.key" diff --git a/scripts/ansible/update_playbook.yml b/scripts/ansible/update_playbook.yml index 478afec..e66dc17 100755 --- a/scripts/ansible/update_playbook.yml +++ b/scripts/ansible/update_playbook.yml @@ -25,6 +25,6 @@ environment: PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin - name: Start node - shell: "nohup {{ ava_binary }} --network-id={{ network_id }} --api-admin-enabled={{ api_admin_enabled }} --api-keystore-enabled={{ api_keystore_enabled }} --api-metrics-enabled={{ api_metrics_enabled }} --ava-tx-fee={{ ava_tx_fee }} --assertions-enabled={{ assertions_enabled }} --signature-verification-enabled={{ signature_verification_enabled }} --db-enabled={{ db_enabled }} --db-dir={{ db_dir }} --http-port={{ http_port }} --http-tls-enabled={{ http_tls_enabled }} --http-tls-key-file={{ http_tls_key_file }} --http-tls-cert-file={{ http_tls_cert_file }} --bootstrap-ips={{ bootstrap_ips }} --bootstrap-ids={{ bootstrap_ids }} --public-ip={{ ansible_host }} --staking-port={{ staking_port }} --staking-tls-enabled={{ staking_tls_enabled }} --staking-tls-key-file={{ staking_tls_key_file }} --staking-tls-cert-file={{ staking_tls_cert_file }} --plugin-dir={{ plugin_dir }} --log-dir={{ log_dir }} --log-level={{ log_level }} --snow-sample-size={{ snow_sample_size }} --snow-quorum-size={{ snow_quorum_size }} --snow-virtuous-commit-threshold={{ snow_virtuous_commit_threshold }} --snow-rogue-commit-threshold={{ snow_rogue_commit_threshold }} --snow-avalanche-num-parents={{ snow_avalanche_num_parents }} --snow-avalanche-batch-size={{ snow_avalanche_batch_size }} --api-ipcs-enabled={{ api_ipcs_enabled }} --xput-server-enabled={{ xput_server_enabled }} --xput-server-port={{ xput_server_port }} >~thelogs.txt 2>&1 &" + shell: "nohup {{ ava_binary }} --network-id={{ network_id }} --api-admin-enabled={{ api_admin_enabled }} --api-keystore-enabled={{ api_keystore_enabled }} --api-metrics-enabled={{ api_metrics_enabled }} --ava-tx-fee={{ ava_tx_fee }} --assertions-enabled={{ assertions_enabled }} --signature-verification-enabled={{ signature_verification_enabled }} --db-enabled={{ db_enabled }} --db-dir={{ db_dir }} --http-port={{ http_port }} --http-tls-enabled={{ http_tls_enabled }} --http-tls-key-file={{ http_tls_key_file }} --http-tls-cert-file={{ http_tls_cert_file }} --bootstrap-ips={{ bootstrap_ips }} --bootstrap-ids={{ bootstrap_ids }} --public-ip={{ ansible_host }} --staking-port={{ staking_port }} --staking-tls-enabled={{ staking_tls_enabled }} --staking-tls-key-file={{ staking_tls_key_file }} --staking-tls-cert-file={{ staking_tls_cert_file }} --plugin-dir={{ plugin_dir }} --log-dir={{ log_dir }} --log-level={{ log_level }} --snow-sample-size={{ snow_sample_size }} --snow-quorum-size={{ snow_quorum_size }} --snow-virtuous-commit-threshold={{ snow_virtuous_commit_threshold }} --snow-rogue-commit-threshold={{ snow_rogue_commit_threshold }} --snow-avalanche-num-parents={{ snow_avalanche_num_parents }} --snow-avalanche-batch-size={{ snow_avalanche_batch_size }} --api-ipcs-enabled={{ api_ipcs_enabled }} --xput-server-enabled={{ xput_server_enabled }} --xput-server-port={{ xput_server_port }} >/dev/null 2>&1 &" environment: PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin From f592ecfb7bd2915dab01e70b283d00205b68d2c0 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Tue, 21 Apr 2020 14:32:00 -0400 Subject: [PATCH 38/61] Don't refresh peers from peerlists if already attempting to connect --- networking/handshake_handlers.go | 20 +++++++++++++++----- node/node.go | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/networking/handshake_handlers.go b/networking/handshake_handlers.go index daa0aff..18476f9 100644 --- a/networking/handshake_handlers.go +++ b/networking/handshake_handlers.go @@ -77,7 +77,7 @@ const ( // ConnectTimeout is the amount of time to wait before attempt to connect to // an unknown peer - ConnectTimeout = time.Second + ConnectTimeout = 6 * time.Second // GetVersionTimeout is the amount of time to wait before sending a // getVersion message to a partially connected peer GetVersionTimeout = 2 * time.Second @@ -222,22 +222,32 @@ func (nm *Handshake) Connect(addr salticidae.NetAddr) { return } - nm.log.Info("Adding peer %s", ip) - if !nm.enableStaking { + nm.log.Info("Adding peer %s", ip) + peer := salticidae.NewPeerIDFromNetAddr(addr, true) nm.ConnectTo(peer, toShortID(ip), addr) return } + nm.requestedLock.Lock() + _, exists := nm.requested[ipStr] + nm.requestedLock.Unlock() + + if exists { + return + } + + nm.log.Info("Adding peer %s", ip) + count := new(int) - *count = 600 + *count = 100 handler := new(func()) *handler = func() { nm.requestedLock.Lock() defer nm.requestedLock.Unlock() - if *count == 600 { + if *count == 100 { nm.requested[ipStr] = struct{}{} } diff --git a/node/node.go b/node/node.go index 2cc7eaa..0f3d105 100644 --- a/node/node.go +++ b/node/node.go @@ -137,7 +137,7 @@ func errorHandler(_err *C.struct_SalticidaeCError, fatal C.bool, asyncID C.int32 MainNode.EC.Stop() return } - MainNode.Log.Error("Error during async with ID %d call: %s", asyncID, salticidae.StrError(err.GetCode())) + MainNode.Log.Debug("Error during async with ID %d call: %s", asyncID, salticidae.StrError(err.GetCode())) } func (n *Node) initNetlib() error { From f1cfa2aa511867175bd938cd84701279cc0740c7 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Wed, 22 Apr 2020 12:46:54 -0400 Subject: [PATCH 39/61] Added server ip + port to error logging --- node/node.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node/node.go b/node/node.go index 0f3d105..d4b2c0e 100644 --- a/node/node.go +++ b/node/node.go @@ -254,7 +254,7 @@ func (n *Node) StartConsensusServer() error { // Listen for P2P messages n.PeerNet.Listen(serverIP, &err) if code := err.GetCode(); code != 0 { - return fmt.Errorf("failed to start consensus server: %s", salticidae.StrError(code)) + return fmt.Errorf("failed to listen on consensus server at %s: %s", n.Config.StakingIP, salticidae.StrError(code)) } // Start a server to handle throughput tests if configuration says to. Disabled by default. @@ -268,7 +268,7 @@ func (n *Node) StartConsensusServer() error { n.ClientNet.Listen(clientIP, &err) if code := err.GetCode(); code != 0 { - return fmt.Errorf("failed to listen on xput server: %s", salticidae.StrError(code)) + return fmt.Errorf("failed to listen on xput server at 127.0.0.1:%d: %s", n.Config.ThroughputPort, salticidae.StrError(code)) } } From a4a171c2190118ea40211f48f329361cbb7cca2e Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Wed, 22 Apr 2020 15:15:48 -0400 Subject: [PATCH 40/61] Changed connTimeout to 60s rather than defaulting to 3m --- node/node.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/node/node.go b/node/node.go index d4b2c0e..3aafae6 100644 --- a/node/node.go +++ b/node/node.go @@ -152,6 +152,8 @@ func (n *Node) initNetlib() error { // Create peer network config, may have tls enabled peerConfig := salticidae.NewPeerNetworkConfig() + peerConfig.ConnTimeout(60) + msgConfig := peerConfig.AsMsgNetworkConfig() msgConfig.MaxMsgSize(maxMessageSize) From 436972b928fd2fd91a184dd3995ec1f1a41d0946 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Wed, 22 Apr 2020 19:52:37 -0400 Subject: [PATCH 41/61] Added kill script --- scripts/ansible/kill_playbook.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 scripts/ansible/kill_playbook.yml diff --git a/scripts/ansible/kill_playbook.yml b/scripts/ansible/kill_playbook.yml new file mode 100755 index 0000000..6e91645 --- /dev/null +++ b/scripts/ansible/kill_playbook.yml @@ -0,0 +1,9 @@ + +--- +- name: Update the network + connection: ssh + gather_facts: false + hosts: all + tasks: + - name: Kill Node + command: killall ava \ No newline at end of file From 2e10a6517fd347cf15a2fb37bd01a50c999baf7b Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 23 Apr 2020 17:55:05 -0400 Subject: [PATCH 42/61] add build successful msg --- scripts/build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/build.sh b/scripts/build.sh index 7000d3f..3e8243c 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -34,3 +34,4 @@ fi go build -o "$PREFIX/ava" "$GECKO_PATH/main/"*.go go build -o "$PREFIX/xputtest" "$GECKO_PATH/xputtest/"*.go go build -o "$PLUGIN_PREFIX/evm" "$CORETH_PATH/plugin/"*.go +echo "Build Successful" \ No newline at end of file From 0865a2d635ac9d4664643d85edce2691776015b4 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Fri, 24 Apr 2020 01:53:02 -0400 Subject: [PATCH 43/61] Removed noop vertices --- snow/engine/avalanche/state/serializer.go | 4 ++ snow/engine/avalanche/state/vertex.go | 5 ++- snow/engine/avalanche/transitive.go | 31 ++++++++++++++- snow/engine/avalanche/transitive_test.go | 48 +++++------------------ 4 files changed, 48 insertions(+), 40 deletions(-) diff --git a/snow/engine/avalanche/state/serializer.go b/snow/engine/avalanche/state/serializer.go index f076548..0034ad1 100644 --- a/snow/engine/avalanche/state/serializer.go +++ b/snow/engine/avalanche/state/serializer.go @@ -82,6 +82,10 @@ func (s *Serializer) ParseVertex(b []byte) (avacon.Vertex, error) { // BuildVertex implements the avalanche.State interface func (s *Serializer) BuildVertex(parentSet ids.Set, txs []snowstorm.Tx) (avacon.Vertex, error) { + if len(txs) == 0 { + return nil, errNoTxs + } + parentIDs := parentSet.List() ids.SortIDs(parentIDs) sortTxs(txs) diff --git a/snow/engine/avalanche/state/vertex.go b/snow/engine/avalanche/state/vertex.go index 928c11c..327a865 100644 --- a/snow/engine/avalanche/state/vertex.go +++ b/snow/engine/avalanche/state/vertex.go @@ -24,6 +24,7 @@ var ( errExtraSpace = errors.New("trailing buffer space") errInvalidParents = errors.New("vertex contains non-sorted or duplicated parentIDs") errInvalidTxs = errors.New("vertex contains non-sorted or duplicated transactions") + errNoTxs = errors.New("vertex contains no transactions") ) type vertex struct { @@ -45,6 +46,8 @@ func (vtx *vertex) Verify() error { switch { case !ids.IsSortedAndUniqueIDs(vtx.parentIDs): return errInvalidParents + case len(vtx.txs) == 0: + return errNoTxs case !isSortedAndUniqueTxs(vtx.txs): return errInvalidTxs default: @@ -55,7 +58,7 @@ func (vtx *vertex) Verify() error { /* * Vertex: * Codec | 04 Bytes - * Chain | 32 Bytes + * Chain | 32 Bytes * Height | 08 Bytes * NumParents | 04 Bytes * Repeated (NumParents): diff --git a/snow/engine/avalanche/transitive.go b/snow/engine/avalanche/transitive.go index 4de2aa5..fc55250 100644 --- a/snow/engine/avalanche/transitive.go +++ b/snow/engine/avalanche/transitive.go @@ -316,8 +316,37 @@ func (t *Transitive) batch(txs []snowstorm.Tx, force, empty bool) { } } - if len(batch) > 0 || (empty && !issued) { + if len(batch) > 0 { t.issueBatch(batch) + } else if empty && !issued { + t.issueRepoll() + } +} + +func (t *Transitive) issueRepoll() { + preferredIDs := t.Consensus.Preferences().List() + numPreferredIDs := len(preferredIDs) + if numPreferredIDs == 0 { + t.Config.Context.Log.Error("Re-query attempt was dropped due to no pending vertices") + return + } + + sampler := random.Uniform{N: len(preferredIDs)} + vtxID := preferredIDs[sampler.Sample()] + + p := t.Consensus.Parameters() + vdrs := t.Config.Validators.Sample(p.K) // Validators to sample + + vdrSet := ids.ShortSet{} // Validators to sample repr. as a set + for _, vdr := range vdrs { + vdrSet.Add(vdr.ID()) + } + + t.RequestID++ + if numVdrs := len(vdrs); numVdrs == p.K && t.polls.Add(t.RequestID, vdrSet.Len()) { + t.Config.Sender.PullQuery(vdrSet, t.RequestID, vtxID) + } else if numVdrs < p.K { + t.Config.Context.Log.Error("Re-query for %s was dropped due to an insufficient number of validators", vtxID) } } diff --git a/snow/engine/avalanche/transitive_test.go b/snow/engine/avalanche/transitive_test.go index defd2df..604afaf 100644 --- a/snow/engine/avalanche/transitive_test.go +++ b/snow/engine/avalanche/transitive_test.go @@ -698,23 +698,12 @@ func TestEngineScheduleRepoll(t *testing.T) { sender.PushQueryF = nil - st.buildVertex = func(_ ids.Set, txs []snowstorm.Tx) (avalanche.Vertex, error) { - consumers := []snowstorm.Tx{} - for _, tx := range txs { - consumers = append(consumers, tx) - } - return &Vtx{ - parents: []avalanche.Vertex{gVtx, mVtx}, - id: GenerateID(), - txs: consumers, - status: choices.Processing, - bytes: []byte{1}, - }, nil - } - repolled := new(bool) - sender.PushQueryF = func(_ ids.ShortSet, _ uint32, _ ids.ID, _ []byte) { + sender.PullQueryF = func(_ ids.ShortSet, _ uint32, vtxID ids.ID) { *repolled = true + if !vtxID.Equals(vtx.ID()) { + t.Fatalf("Wrong vertex queried") + } } te.QueryFailed(vdr.ID(), *requestID) @@ -979,31 +968,14 @@ func TestEngineIssueRepoll(t *testing.T) { te.Initialize(config) te.finishBootstrapping() - newVtxID := new(ids.ID) - - st.buildVertex = func(s ids.Set, txs []snowstorm.Tx) (avalanche.Vertex, error) { - if len(txs) != 0 { - t.Fatalf("Wrong vertex issued") - } - if s.Len() != 2 || !s.Contains(gVtx.ID()) || !s.Contains(mVtx.ID()) { - t.Fatalf("Wrong vertex issued") - } - - vtx := &Vtx{ - parents: []avalanche.Vertex{gVtx, mVtx}, - id: GenerateID(), - status: choices.Processing, - bytes: []byte{1}, - } - *newVtxID = vtx.ID() - return vtx, nil - } - - sender.PushQueryF = func(vdrs ids.ShortSet, _ uint32, vtxID ids.ID, vtx []byte) { + sender.PullQueryF = func(vdrs ids.ShortSet, _ uint32, vtxID ids.ID) { vdrSet := ids.ShortSet{} vdrSet.Add(vdr.ID()) - if !vdrs.Equals(vdrSet) || !vtxID.Equals(*newVtxID) { - t.Fatalf("Wrong query message") + if !vdrs.Equals(vdrSet) { + t.Fatalf("Wrong query recipients") + } + if !vtxID.Equals(gVtx.ID()) && !vtxID.Equals(mVtx.ID()) { + t.Fatalf("Unknown re-query") } } From 4b077209d53104c50baa625b17464cd30eea8f0b Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Fri, 24 Apr 2020 14:44:04 -0400 Subject: [PATCH 44/61] Updated client version --- main/params.go | 6 ++- networking/handshake_handlers.go | 83 ++++++++++++++++++++++++++++---- 2 files changed, 78 insertions(+), 11 deletions(-) diff --git a/main/params.go b/main/params.go index f5155a0..68b63c4 100644 --- a/main/params.go +++ b/main/params.go @@ -26,6 +26,10 @@ import ( "github.com/ava-labs/gecko/utils/wrappers" ) +const ( + dbVersion = "v0.1.0" +) + // Results of parsing the CLI var ( Config = node.Config{} @@ -143,7 +147,7 @@ func init() { // DB: if *db && err == nil { // TODO: Add better params here - dbPath := path.Join(*dbDir, genesis.NetworkName(Config.NetworkID)) + dbPath := path.Join(*dbDir, genesis.NetworkName(Config.NetworkID), dbVersion) db, err := leveldb.New(dbPath, 0, 0, 0) Config.DB = db errs.Add(err) diff --git a/networking/handshake_handlers.go b/networking/handshake_handlers.go index 18476f9..a2c9f57 100644 --- a/networking/handshake_handlers.go +++ b/networking/handshake_handlers.go @@ -19,6 +19,8 @@ import ( "errors" "fmt" "math" + "strconv" + "strings" "sync" "time" "unsafe" @@ -61,9 +63,23 @@ Attempt reconnections node isn't connected to after awhile delete the connection. */ +// Version this avalanche instance is executing. +var ( + VersionPrefix = "avalanche/" + VersionSeparator = "." + MajorVersion = 0 + MinorVersion = 1 + PatchVersion = 0 + ClientVersion = fmt.Sprintf("%s%d%s%d%s%d", + VersionPrefix, + MajorVersion, + VersionSeparator, + MinorVersion, + VersionSeparator, + PatchVersion) +) + const ( - // CurrentVersion this avalanche instance is executing. - CurrentVersion = "avalanche/0.0.1" // MaxClockDifference allowed between connected nodes. MaxClockDifference = time.Minute // PeerListGossipSpacing is the amount of time to wait between pushing this @@ -356,7 +372,7 @@ func (nm *Handshake) SendGetVersion(peer salticidae.PeerID) { // SendVersion to the requested peer func (nm *Handshake) SendVersion(peer salticidae.PeerID) error { build := Builder{} - v, err := build.Version(nm.networkID, nm.clock.Unix(), toIPDesc(nm.myAddr), CurrentVersion) + v, err := build.Version(nm.networkID, nm.clock.Unix(), toIPDesc(nm.myAddr), ClientVersion) if err != nil { return fmt.Errorf("packing Version failed due to %s", err) } @@ -518,6 +534,59 @@ func (nm *Handshake) disconnectedFromPeer(peer salticidae.PeerID) { } } +// checkCompatibility Check to make sure that the peer and I speak the same language. +func (nm *Handshake) checkCompatibility(peerVersion string) bool { + if !strings.HasPrefix(peerVersion, VersionPrefix) { + nm.log.Warn("Peer attempted to connect with an invalid version prefix") + return false + } + peerVersion = peerVersion[len(VersionPrefix):] + splitPeerVersion := strings.SplitN(peerVersion, VersionSeparator, 3) + if len(splitPeerVersion) != 3 { + nm.log.Warn("Peer attempted to connect with an invalid number of subversions") + return false + } + + major, err := strconv.Atoi(splitPeerVersion[0]) + if err != nil { + nm.log.Warn("Peer attempted to connect with an invalid major version") + return false + } + minor, err := strconv.Atoi(splitPeerVersion[1]) + if err != nil { + nm.log.Warn("Peer attempted to connect with an invalid minor version") + return false + } + patch, err := strconv.Atoi(splitPeerVersion[2]) + if err != nil { + nm.log.Warn("Peer attempted to connect with an invalid patch version") + return false + } + + switch { + case major < MajorVersion: + // peers major version is too low + return false + case major > MajorVersion: + nm.log.Warn("Peer attempted to connect with a higher major version, this client may need to be updated") + return false + } + + switch { + case minor < MinorVersion: + // peers minor version is too low + return false + case minor > MinorVersion: + nm.log.Warn("Peer attempted to connect with a higher minor version, this client may need to be updated") + return false + } + + if patch > PatchVersion { + nm.log.Warn("Peer is connecting with a higher patch version, this client may need to be updated") + } + return true +} + // peerHandler notifies a change to the set of connected peers // connected is true if a new peer is connected // connected is false if a formerly connected peer has disconnected @@ -645,7 +714,7 @@ func version(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe.P return } - if peerVersion := pMsg.Get(VersionStr).(string); !checkCompatibility(CurrentVersion, peerVersion) { + if peerVersion := pMsg.Get(VersionStr).(string); !HandshakeNet.checkCompatibility(peerVersion) { HandshakeNet.log.Warn("Bad version") HandshakeNet.net.DelPeer(peer) @@ -741,12 +810,6 @@ func getCert(cert salticidae.X509) ids.ShortID { return certID } -// checkCompatibility Check to make sure that the peer and I speak the same language. -func checkCompatibility(myVersion string, peerVersion string) bool { - // At the moment, we are all compatible. - return true -} - func toShortID(ip utils.IPDesc) ids.ShortID { return ids.NewShortID(hashing.ComputeHash160Array([]byte(ip.String()))) } From 6f6919cf1b2fff4bfa070d42d4d524545d9637c3 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Fri, 24 Apr 2020 15:03:29 -0400 Subject: [PATCH 45/61] Updated invalid peer version comment --- networking/handshake_handlers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/networking/handshake_handlers.go b/networking/handshake_handlers.go index a2c9f57..9e0c9cf 100644 --- a/networking/handshake_handlers.go +++ b/networking/handshake_handlers.go @@ -715,7 +715,7 @@ func version(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe.P } if peerVersion := pMsg.Get(VersionStr).(string); !HandshakeNet.checkCompatibility(peerVersion) { - HandshakeNet.log.Warn("Bad version") + HandshakeNet.log.Debug("Dropping connection due to an incompatible version from peer") HandshakeNet.net.DelPeer(peer) return From 7d6b8a5f995ebedb22e5323d0cf074d9e2c29e64 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 24 Apr 2020 20:44:51 +0100 Subject: [PATCH 46/61] snow: Use backtick strings to avoid escaping Brady Goat banner Much nicer on the eye IMHO --- snow/consensus/snowball/parameters.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/snow/consensus/snowball/parameters.go b/snow/consensus/snowball/parameters.go index 7d77405..230f2d7 100644 --- a/snow/consensus/snowball/parameters.go +++ b/snow/consensus/snowball/parameters.go @@ -10,20 +10,21 @@ import ( ) const ( - errMsg = "__________ .___\n" + - "\\______ \\____________ __| _/__.__.\n" + - " | | _/\\_ __ \\__ \\ / __ < | |\n" + - " | | \\ | | \\// __ \\_/ /_/ |\\___ |\n" + - " |______ / |__| (____ /\\____ |/ ____|\n" + - " \\/ \\/ \\/\\/\n" + + errMsg = "" + + `__________ .___` + "\n" + + `\______ \____________ __| _/__.__.` + "\n" + + ` | | _/\_ __ \__ \ / __ < | |` + "\n" + + ` | | \ | | \// __ \_/ /_/ |\___ |` + "\n" + + ` |______ / |__| (____ /\____ |/ ____|` + "\n" + + ` \/ \/ \/\/` + "\n" + "\n" + - "🏆 🏆 🏆 🏆 🏆 🏆\n" + - " ________ ________ ________________\n" + - " / _____/ \\_____ \\ / _ \\__ ___/\n" + - "/ \\ ___ / | \\ / /_\\ \\| |\n" + - "\\ \\_\\ \\/ | \\/ | \\ |\n" + - " \\______ /\\_______ /\\____|__ /____|\n" + - " \\/ \\/ \\/\n" + `🏆 🏆 🏆 🏆 🏆 🏆` + "\n" + + ` ________ ________ ________________` + "\n" + + ` / _____/ \_____ \ / _ \__ ___/` + "\n" + + `/ \ ___ / | \ / /_\ \| |` + "\n" + + `\ \_\ \/ | \/ | \ |` + "\n" + + ` \______ /\_______ /\____|__ /____|` + "\n" + + ` \/ \/ \/` + "\n" ) // Parameters required for snowball consensus From b1ea742cf22f117dd613f010041b6d523b5475ac Mon Sep 17 00:00:00 2001 From: Anil Dasari Date: Fri, 24 Apr 2020 13:01:42 -0700 Subject: [PATCH 47/61] minor fixes --- ids/id_test.go | 2 +- vms/platformvm/service.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ids/id_test.go b/ids/id_test.go index b541ed5..512952b 100644 --- a/ids/id_test.go +++ b/ids/id_test.go @@ -152,7 +152,7 @@ func TestIDHex(t *testing.T) { id := NewID([32]byte{'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'}) expected := "617661206c61627300000000000000000000000000000000000000000000000000" actual := id.Hex() - if actual != actual { + if actual != expected { t.Fatalf("got %s, expected %s", actual, expected) } } diff --git a/vms/platformvm/service.go b/vms/platformvm/service.go index b911c2a..86093b0 100644 --- a/vms/platformvm/service.go +++ b/vms/platformvm/service.go @@ -1227,6 +1227,10 @@ func (service *Service) chainExists(blockID ids.ID, chainID ids.ID) (bool, error db := block.onAccept() chains, err := service.vm.getChains(db) + if err != nil { + return false, err + } + for _, chain := range chains { if chain.ID().Equals(chainID) { return true, nil From 628856992fda7cd30a9b0d3bd195adda202818f0 Mon Sep 17 00:00:00 2001 From: Anil Dasari Date: Fri, 24 Apr 2020 13:23:07 -0700 Subject: [PATCH 48/61] added warn log incase of addroute failure --- vms/manager.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vms/manager.go b/vms/manager.go index 9f8cf3b..4449c27 100644 --- a/vms/manager.go +++ b/vms/manager.go @@ -131,6 +131,8 @@ func (m *manager) addStaticAPIEndpoints(vmID ids.ID) { // register the static endpoints for extension, service := range staticVM.CreateStaticHandlers() { m.log.Verbo("adding static API endpoint: %s", defaultEndpoint+extension) - m.apiServer.AddRoute(service, lock, defaultEndpoint, extension, m.log) + if err := m.apiServer.AddRoute(service, lock, defaultEndpoint, extension, m.log); err != nil { + m.log.Warn("failed to add static API endpoint %s: %v", fmt.Sprintf("%s%s", defaultEndpoint, extension), err) + } } } From bbe250c529818581d352809e3dbcf00468b6602e Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Fri, 24 Apr 2020 16:24:10 -0400 Subject: [PATCH 49/61] endtime -> endTime --- vms/platformvm/service_test.go | 2 +- vms/platformvm/static_service.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 6efb8d6..051c2c0 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -9,7 +9,7 @@ import ( ) func TestAddDefaultSubnetValidator(t *testing.T) { - expectedJSONString := `{"startTime":"0","endtime":"0","id":null,"destination":null,"delegationFeeRate":"0","payerNonce":"0"}` + expectedJSONString := `{"startTime":"0","endTime":"0","id":null,"destination":null,"delegationFeeRate":"0","payerNonce":"0"}` args := AddDefaultSubnetValidatorArgs{} bytes, err := json.Marshal(&args) if err != nil { diff --git a/vms/platformvm/static_service.go b/vms/platformvm/static_service.go index 80b66d2..86af005 100644 --- a/vms/platformvm/static_service.go +++ b/vms/platformvm/static_service.go @@ -44,7 +44,7 @@ type APIAccount struct { // is sent when this staker is done staking. type APIValidator struct { StartTime json.Uint64 `json:"startTime"` - EndTime json.Uint64 `json:"endtime"` + EndTime json.Uint64 `json:"endTime"` Weight *json.Uint64 `json:"weight,omitempty"` StakeAmount *json.Uint64 `json:"stakeAmount,omitempty"` ID ids.ShortID `json:"id"` From 737087f0ca84b30d67fd222623161b43fa1f293a Mon Sep 17 00:00:00 2001 From: Anil Dasari Date: Fri, 24 Apr 2020 13:31:12 -0700 Subject: [PATCH 50/61] error check and go fmt --- vms/avm/vm.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/vms/avm/vm.go b/vms/avm/vm.go index c8b33f1..af87871 100644 --- a/vms/avm/vm.go +++ b/vms/avm/vm.go @@ -91,8 +91,10 @@ func (cr *codecRegistry) RegisterType(val interface{}) error { cr.typeToFxIndex[valType] = cr.index return cr.codec.RegisterType(val) } -func (cr *codecRegistry) Marshal(val interface{}) ([]byte, error) { return cr.codec.Marshal(val) } -func (cr *codecRegistry) Unmarshal(b []byte, val interface{}) error { return cr.codec.Unmarshal(b, val) } +func (cr *codecRegistry) Marshal(val interface{}) ([]byte, error) { return cr.codec.Marshal(val) } +func (cr *codecRegistry) Unmarshal(b []byte, val interface{}) error { + return cr.codec.Unmarshal(b, val) +} /* ****************************************************************************** @@ -456,7 +458,10 @@ func (vm *VM) parseTx(b []byte) (*UniqueTx, error) { if err := vm.state.SetTx(tx.ID(), tx.Tx); err != nil { return nil, err } - tx.setStatus(choices.Processing) + + if err := tx.setStatus(choices.Processing); err != nil { + return nil, err + } } return tx, nil From 88228ac1d61b7508cefe1da162de1d36c85b6a5b Mon Sep 17 00:00:00 2001 From: Anil Dasari Date: Fri, 24 Apr 2020 13:42:36 -0700 Subject: [PATCH 51/61] error check --- vms/avm/vm.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vms/avm/vm.go b/vms/avm/vm.go index af87871..a46244d 100644 --- a/vms/avm/vm.go +++ b/vms/avm/vm.go @@ -389,7 +389,9 @@ func (vm *VM) initAliases(genesisBytes []byte) error { txID := tx.ID() - vm.Alias(txID, genesisTx.Alias) + if err = vm.Alias(txID, genesisTx.Alias); err != nil { + return err + } } return nil From 5440369118b764892bdc9c44617b31c60f74087a Mon Sep 17 00:00:00 2001 From: Anil Dasari Date: Fri, 24 Apr 2020 14:47:05 -0700 Subject: [PATCH 52/61] static analyis fixes --- vms/components/codec/codec.go | 5 +---- vms/components/core/snowman_vm.go | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/vms/components/codec/codec.go b/vms/components/codec/codec.go index 8005f34..72192cb 100644 --- a/vms/components/codec/codec.go +++ b/vms/components/codec/codec.go @@ -341,8 +341,5 @@ func (c codec) unmarshal(p *wrappers.Packer, field reflect.Value) error { // Returns true iff [field] should be serialized func shouldSerialize(field reflect.StructField) bool { - if field.Tag.Get("serialize") == "true" { - return true - } - return false + return field.Tag.Get("serialize") == "true" } diff --git a/vms/components/core/snowman_vm.go b/vms/components/core/snowman_vm.go index f710edd..bc849af 100644 --- a/vms/components/core/snowman_vm.go +++ b/vms/components/core/snowman_vm.go @@ -95,10 +95,7 @@ func (svm *SnowmanVM) Shutdown() { // DBInitialized returns true iff [svm]'s database has values in it already func (svm *SnowmanVM) DBInitialized() bool { status := svm.State.GetStatus(svm.DB, dbInitializedID) - if status == choices.Accepted { - return true - } - return false + return status == choices.Accepted } // SetDBInitialized marks the database as initialized From 8b76cf601ef43f9c90c41997dfc123aa154bf59c Mon Sep 17 00:00:00 2001 From: Anil Dasari Date: Fri, 24 Apr 2020 14:54:24 -0700 Subject: [PATCH 53/61] replaced loop --- snow/engine/avalanche/bootstrapper.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/snow/engine/avalanche/bootstrapper.go b/snow/engine/avalanche/bootstrapper.go index 7bacd46..0fd86a3 100644 --- a/snow/engine/avalanche/bootstrapper.go +++ b/snow/engine/avalanche/bootstrapper.go @@ -177,9 +177,7 @@ func (b *bootstrapper) storeVertex(vtx avalanche.Vertex) { } } - for _, parent := range vtx.Parents() { - vts = append(vts, parent) - } + vts = append(vts, vtx.Parents()...) case choices.Accepted: b.BootstrapConfig.Context.Log.Verbo("Bootstrapping confirmed %s", vtxID) case choices.Rejected: From f2c4c8195d5ae23a3e0fa9d4ad650ffa61feed01 Mon Sep 17 00:00:00 2001 From: Anil Dasari Date: Fri, 24 Apr 2020 21:15:31 -0700 Subject: [PATCH 54/61] testcase fix --- ids/id_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ids/id_test.go b/ids/id_test.go index 512952b..c43dc3a 100644 --- a/ids/id_test.go +++ b/ids/id_test.go @@ -150,7 +150,7 @@ func TestIDUnmarshalJSON(t *testing.T) { func TestIDHex(t *testing.T) { id := NewID([32]byte{'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'}) - expected := "617661206c61627300000000000000000000000000000000000000000000000000" + expected := "617661206c616273000000000000000000000000000000000000000000000000" actual := id.Hex() if actual != expected { t.Fatalf("got %s, expected %s", actual, expected) From 592fb896fffcd4319abf241e0522c8e9979d60e2 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Sun, 26 Apr 2020 14:28:36 -0400 Subject: [PATCH 55/61] check that binaries actually exist --- scripts/build.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/build.sh b/scripts/build.sh index 3e8243c..46147a9 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -34,4 +34,8 @@ fi go build -o "$PREFIX/ava" "$GECKO_PATH/main/"*.go go build -o "$PREFIX/xputtest" "$GECKO_PATH/xputtest/"*.go go build -o "$PLUGIN_PREFIX/evm" "$CORETH_PATH/plugin/"*.go -echo "Build Successful" \ No newline at end of file +if [[ -f "$PREFIX/ava" && -f "$PREFIX/xputtest" && -f "$PLUGIN_PREFIX/evm" ]]; then + echo "Build Successful" +else + echo "Build failure" +fi \ No newline at end of file From 9580a3bf0f60f1d7c08dc2df47f4ab3a2acb3ebc Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Tue, 28 Apr 2020 12:31:04 -0400 Subject: [PATCH 56/61] Fixed platform vm writeback of ProposalBlocks --- vms/platformvm/abort_block.go | 14 +-- vms/platformvm/atomic_block.go | 8 +- vms/platformvm/commit_block.go | 14 +-- vms/platformvm/common_blocks.go | 70 ++++++++--- vms/platformvm/proposal_block.go | 4 + vms/platformvm/standard_block.go | 14 +-- vms/platformvm/vm.go | 64 ++++++---- vms/platformvm/vm_test.go | 200 +++++++++++++++++++++++++++++++ 8 files changed, 322 insertions(+), 66 deletions(-) diff --git a/vms/platformvm/abort_block.go b/vms/platformvm/abort_block.go index cb08d02..168fc2d 100644 --- a/vms/platformvm/abort_block.go +++ b/vms/platformvm/abort_block.go @@ -11,7 +11,7 @@ import ( // Abort being accepted results in the proposal of its parent (which must be a proposal block) // being rejected. type Abort struct { - CommonDecisionBlock `serialize:"true"` + DoubleDecisionBlock `serialize:"true"` } // Verify this block performs a valid state transition. @@ -35,14 +35,10 @@ func (a *Abort) Verify() error { // newAbortBlock returns a new *Abort block where the block's parent, a proposal // block, has ID [parentID]. func (vm *VM) newAbortBlock(parentID ids.ID) *Abort { - abort := &Abort{ - CommonDecisionBlock: CommonDecisionBlock{ - CommonBlock: CommonBlock{ - Block: core.NewBlock(parentID), - vm: vm, - }, - }, - } + abort := &Abort{DoubleDecisionBlock: DoubleDecisionBlock{CommonDecisionBlock: CommonDecisionBlock{CommonBlock: CommonBlock{ + Block: core.NewBlock(parentID), + vm: vm, + }}}} // We serialize this block as a Block so that it can be deserialized into a // Block diff --git a/vms/platformvm/atomic_block.go b/vms/platformvm/atomic_block.go index 8b973ad..20c2892 100644 --- a/vms/platformvm/atomic_block.go +++ b/vms/platformvm/atomic_block.go @@ -36,7 +36,7 @@ type AtomicTx interface { // AtomicBlock being accepted results in the transaction contained in the // block to be accepted and committed to the chain. type AtomicBlock struct { - CommonDecisionBlock `serialize:"true"` + SingleDecisionBlock `serialize:"true"` Tx AtomicTx `serialize:"true"` @@ -45,7 +45,7 @@ type AtomicBlock struct { // initialize this block func (ab *AtomicBlock) initialize(vm *VM, bytes []byte) error { - if err := ab.CommonDecisionBlock.initialize(vm, bytes); err != nil { + if err := ab.SingleDecisionBlock.initialize(vm, bytes); err != nil { return err } return ab.Tx.initialize(vm) @@ -133,12 +133,12 @@ func (ab *AtomicBlock) Accept() { // decision block, has ID [parentID]. func (vm *VM) newAtomicBlock(parentID ids.ID, tx AtomicTx) (*AtomicBlock, error) { ab := &AtomicBlock{ - CommonDecisionBlock: CommonDecisionBlock{ + SingleDecisionBlock: SingleDecisionBlock{CommonDecisionBlock: CommonDecisionBlock{ CommonBlock: CommonBlock{ Block: core.NewBlock(parentID), vm: vm, }, - }, + }}, Tx: tx, } diff --git a/vms/platformvm/commit_block.go b/vms/platformvm/commit_block.go index 63fc8db..00f746f 100644 --- a/vms/platformvm/commit_block.go +++ b/vms/platformvm/commit_block.go @@ -11,7 +11,7 @@ import ( // Commit being accepted results in the proposal of its parent (which must be a proposal block) // being enacted. type Commit struct { - CommonDecisionBlock `serialize:"true"` + DoubleDecisionBlock `serialize:"true"` } // Verify this block performs a valid state transition. @@ -35,14 +35,10 @@ func (c *Commit) Verify() error { // newCommitBlock returns a new *Commit block where the block's parent, a // proposal block, has ID [parentID]. func (vm *VM) newCommitBlock(parentID ids.ID) *Commit { - commit := &Commit{ - CommonDecisionBlock: CommonDecisionBlock{ - CommonBlock: CommonBlock{ - Block: core.NewBlock(parentID), - vm: vm, - }, - }, - } + commit := &Commit{DoubleDecisionBlock: DoubleDecisionBlock{CommonDecisionBlock: CommonDecisionBlock{CommonBlock: CommonBlock{ + Block: core.NewBlock(parentID), + vm: vm, + }}}} // We serialize this block as a Block so that it can be deserialized into a // Block diff --git a/vms/platformvm/common_blocks.go b/vms/platformvm/common_blocks.go index 0d05911..a50dd2a 100644 --- a/vms/platformvm/common_blocks.go +++ b/vms/platformvm/common_blocks.go @@ -185,7 +185,6 @@ func (cb *CommonBlock) parentBlock() Block { func (cb *CommonBlock) addChild(child Block) { cb.children = append(cb.children, child) } // CommonDecisionBlock contains the fields and methods common to all decision blocks -// (ie *Commit and *Abort) type CommonDecisionBlock struct { CommonBlock `serialize:"true"` @@ -220,29 +219,70 @@ func (cdb *CommonDecisionBlock) onAccept() database.Database { return cdb.onAcceptDB } -// Accept implements the snowman.Block interface -func (cdb *CommonDecisionBlock) Accept() { - cdb.VM.Ctx.Log.Verbo("Accepting block with ID %s", cdb.ID()) +// SingleDecisionBlock contains the accept for standalone decision blocks +type SingleDecisionBlock struct { + CommonDecisionBlock `serialize:"true"` +} - cdb.CommonBlock.Accept() +// Accept implements the snowman.Block interface +func (sdb *SingleDecisionBlock) Accept() { + sdb.VM.Ctx.Log.Verbo("Accepting block with ID %s", sdb.ID()) + + sdb.CommonBlock.Accept() // Update the state of the chain in the database - if err := cdb.onAcceptDB.Commit(); err != nil { - cdb.vm.Ctx.Log.Warn("unable to commit onAcceptDB") + if err := sdb.onAcceptDB.Commit(); err != nil { + sdb.vm.Ctx.Log.Warn("unable to commit onAcceptDB") } - if err := cdb.vm.DB.Commit(); err != nil { - cdb.vm.Ctx.Log.Warn("unable to commit vm's DB") + if err := sdb.vm.DB.Commit(); err != nil { + sdb.vm.Ctx.Log.Warn("unable to commit vm's DB") } - for _, child := range cdb.children { - child.setBaseDatabase(cdb.vm.DB) + for _, child := range sdb.children { + child.setBaseDatabase(sdb.vm.DB) } - if cdb.onAcceptFunc != nil { - cdb.onAcceptFunc() + if sdb.onAcceptFunc != nil { + sdb.onAcceptFunc() + } + + sdb.free() +} + +// DoubleDecisionBlock contains the accept for a pair of blocks +type DoubleDecisionBlock struct { + CommonDecisionBlock `serialize:"true"` +} + +// Accept implements the snowman.Block interface +func (ddb *DoubleDecisionBlock) Accept() { + ddb.VM.Ctx.Log.Verbo("Accepting block with ID %s", ddb.ID()) + + parent, ok := ddb.parentBlock().(*ProposalBlock) + if !ok { + ddb.vm.Ctx.Log.Error("double decision block should only follow a proposal block") + return + } + + parent.CommonBlock.Accept() + + ddb.CommonBlock.Accept() + + // Update the state of the chain in the database + if err := ddb.onAcceptDB.Commit(); err != nil { + ddb.vm.Ctx.Log.Warn("unable to commit onAcceptDB") + } + if err := ddb.vm.DB.Commit(); err != nil { + ddb.vm.Ctx.Log.Warn("unable to commit vm's DB") + } + + for _, child := range ddb.children { + child.setBaseDatabase(ddb.vm.DB) + } + if ddb.onAcceptFunc != nil { + ddb.onAcceptFunc() } - parent := cdb.parentBlock() // remove this block and its parent from memory parent.free() - cdb.free() + ddb.free() } diff --git a/vms/platformvm/proposal_block.go b/vms/platformvm/proposal_block.go index afa3f93..5ddfe3f 100644 --- a/vms/platformvm/proposal_block.go +++ b/vms/platformvm/proposal_block.go @@ -7,6 +7,7 @@ import ( "github.com/ava-labs/gecko/database" "github.com/ava-labs/gecko/database/versiondb" "github.com/ava-labs/gecko/ids" + "github.com/ava-labs/gecko/snow/choices" "github.com/ava-labs/gecko/snow/consensus/snowman" "github.com/ava-labs/gecko/vms/components/core" ) @@ -41,6 +42,9 @@ type ProposalBlock struct { onAbortFunc func() } +// Accept implements the snowman.Block interface +func (pb *ProposalBlock) Accept() { pb.SetStatus(choices.Accepted) } + // Initialize this block. // Sets [pb.vm] to [vm] and populates non-serialized fields // This method should be called when a block is unmarshaled from bytes diff --git a/vms/platformvm/standard_block.go b/vms/platformvm/standard_block.go index 5f7e300..243d074 100644 --- a/vms/platformvm/standard_block.go +++ b/vms/platformvm/standard_block.go @@ -25,14 +25,14 @@ type DecisionTx interface { // StandardBlock being accepted results in the transactions contained in the // block to be accepted and committed to the chain. type StandardBlock struct { - CommonDecisionBlock `serialize:"true"` + SingleDecisionBlock `serialize:"true"` Txs []DecisionTx `serialize:"true"` } // initialize this block func (sb *StandardBlock) initialize(vm *VM, bytes []byte) error { - if err := sb.CommonDecisionBlock.initialize(vm, bytes); err != nil { + if err := sb.SingleDecisionBlock.initialize(vm, bytes); err != nil { return err } for _, tx := range sb.Txs { @@ -90,12 +90,10 @@ func (sb *StandardBlock) Verify() error { // decision block, has ID [parentID]. func (vm *VM) newStandardBlock(parentID ids.ID, txs []DecisionTx) (*StandardBlock, error) { sb := &StandardBlock{ - CommonDecisionBlock: CommonDecisionBlock{ - CommonBlock: CommonBlock{ - Block: core.NewBlock(parentID), - vm: vm, - }, - }, + SingleDecisionBlock: SingleDecisionBlock{CommonDecisionBlock: CommonDecisionBlock{CommonBlock: CommonBlock{ + Block: core.NewBlock(parentID), + vm: vm, + }}}, Txs: txs, } diff --git a/vms/platformvm/vm.go b/vms/platformvm/vm.go index 3e4bf78..9fdf153 100644 --- a/vms/platformvm/vm.go +++ b/vms/platformvm/vm.go @@ -81,22 +81,23 @@ var ( ) var ( - errEndOfTime = errors.New("program time is suspiciously far in the future. Either this codebase was way more successful than expected, or a critical error has occurred") - errTimeTooAdvanced = errors.New("this is proposing a time too far in the future") - errNoPendingBlocks = errors.New("no pending blocks") - errUnsupportedFXs = errors.New("unsupported feature extensions") - errDB = errors.New("problem retrieving/putting value from/in database") - errDBCurrentValidators = errors.New("couldn't retrieve current validators from database") - errDBPutCurrentValidators = errors.New("couldn't put current validators in database") - errDBPendingValidators = errors.New("couldn't retrieve pending validators from database") - errDBPutPendingValidators = errors.New("couldn't put pending validators in database") - errDBAccount = errors.New("couldn't retrieve account from database") - errDBPutAccount = errors.New("couldn't put account in database") - errDBChains = errors.New("couldn't retrieve chain list from database") - errDBPutChains = errors.New("couldn't put chain list in database") - errDBPutBlock = errors.New("couldn't put block in database") - errRegisteringType = errors.New("error registering type with database") - errMissingBlock = errors.New("missing block") + errEndOfTime = errors.New("program time is suspiciously far in the future. Either this codebase was way more successful than expected, or a critical error has occurred") + errTimeTooAdvanced = errors.New("this is proposing a time too far in the future") + errNoPendingBlocks = errors.New("no pending blocks") + errUnsupportedFXs = errors.New("unsupported feature extensions") + errDB = errors.New("problem retrieving/putting value from/in database") + errDBCurrentValidators = errors.New("couldn't retrieve current validators from database") + errDBPutCurrentValidators = errors.New("couldn't put current validators in database") + errDBPendingValidators = errors.New("couldn't retrieve pending validators from database") + errDBPutPendingValidators = errors.New("couldn't put pending validators in database") + errDBAccount = errors.New("couldn't retrieve account from database") + errDBPutAccount = errors.New("couldn't put account in database") + errDBChains = errors.New("couldn't retrieve chain list from database") + errDBPutChains = errors.New("couldn't put chain list in database") + errDBPutBlock = errors.New("couldn't put block in database") + errRegisteringType = errors.New("error registering type with database") + errMissingBlock = errors.New("missing block") + errInvalidLastAcceptedBlock = errors.New("last accepted block must be a decision block") ) // Codec does serialization and deserialization @@ -287,6 +288,10 @@ func (vm *VM) Initialize( genesisBlock.CommonBlock.Accept() vm.SetDBInitialized() + + if err := vm.DB.Commit(); err != nil { + return errDB + } } // Transactions from clients that have not yet been put into blocks @@ -313,8 +318,22 @@ func (vm *VM) Initialize( return err } + lastAcceptedID := vm.LastAccepted() + vm.Ctx.Log.Info("Initializing last accepted block as %s", lastAcceptedID) + // Build off the most recently accepted block - vm.SetPreference(vm.LastAccepted()) + vm.SetPreference(lastAcceptedID) + + // Sanity check to make sure the DB is in a valid state + lastAcceptedIntf, err := vm.getBlock(lastAcceptedID) + if err != nil { + vm.Ctx.Log.Error("Error fetching the last accepted block (%s), %s", vm.Preferred(), err) + return err + } + if _, ok := lastAcceptedIntf.(decision); !ok { + vm.Ctx.Log.Fatal("The last accepted block, %s, must always be a decision block", lastAcceptedID) + return errInvalidLastAcceptedBlock + } return nil } @@ -609,16 +628,19 @@ func (vm *VM) resetTimer() { } // Get the preferred block - preferred, err := vm.getBlock(vm.Preferred()) - vm.Ctx.Log.AssertNoError(err) + preferredIntf, err := vm.getBlock(vm.Preferred()) + if err != nil { + vm.Ctx.Log.Error("Error fetching the preferred block (%s), %s", vm.Preferred(), err) + return + } // The database if the preferred block were to be committed var db database.Database // The preferred block should always be a decision block - if preferred, ok := preferred.(decision); ok { + if preferred, ok := preferredIntf.(decision); ok { db = preferred.onAccept() } else { - vm.Ctx.Log.Error("The preferred block should always be a decision block") + vm.Ctx.Log.Error("The preferred block, %s, should always be a decision block", vm.Preferred()) return } diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index e0af19f..9c9e467 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -1227,3 +1227,203 @@ func TestOptimisticAtomicImport(t *testing.T) { t.Fatalf("failed to provide funds") } } + +// test restarting the node +func TestRestartPartiallyAccepted(t *testing.T) { + genesisAccounts := GenesisAccounts() + genesisValidators := GenesisCurrentValidators() + genesisChains := make([]*CreateChainTx, 0) + + genesisState := Genesis{ + Accounts: genesisAccounts, + Validators: genesisValidators, + Chains: genesisChains, + Timestamp: uint64(defaultGenesisTime.Unix()), + } + + genesisBytes, err := Codec.Marshal(genesisState) + if err != nil { + t.Fatal(err) + } + + db := memdb.New() + + firstVM := &VM{ + SnowmanVM: &core.SnowmanVM{}, + chainManager: chains.MockManager{}, + } + + firstDefaultSubnet := validators.NewSet() + firstVM.validators = validators.NewManager() + firstVM.validators.PutValidatorSet(DefaultSubnetID, firstDefaultSubnet) + + firstVM.clock.Set(defaultGenesisTime) + firstCtx := defaultContext() + firstMsgChan := make(chan common.Message, 1) + if err := firstVM.Initialize(firstCtx, db, genesisBytes, firstMsgChan, nil); err != nil { + t.Fatal(err) + } + + genesisID := firstVM.LastAccepted() + + firstAdvanceTimeTx, err := firstVM.newAdvanceTimeTx(defaultGenesisTime.Add(time.Second)) + if err != nil { + t.Fatal(err) + } + firstAdvanceTimeBlk, err := firstVM.newProposalBlock(firstVM.Preferred(), firstAdvanceTimeTx) + if err != nil { + t.Fatal(err) + } + + firstVM.clock.Set(defaultGenesisTime.Add(2 * time.Second)) + if err := firstAdvanceTimeBlk.Verify(); err != nil { + t.Fatal(err) + } + + options := firstAdvanceTimeBlk.Options() + firstOption := options[0] + secondOption := options[1] + + if err := firstOption.Verify(); err != nil { + t.Fatal(err) + } + if err := secondOption.Verify(); err != nil { + t.Fatal(err) + } + + firstAdvanceTimeBlk.Accept() + + secondAdvanceTimeBlkBytes := []byte{ + 0x00, 0x00, 0x00, 0x00, 0xad, 0x64, 0x34, 0x49, + 0xa5, 0x05, 0xd8, 0xda, 0xc6, 0xd1, 0xb8, 0x2c, + 0x5c, 0xe6, 0x06, 0x81, 0xf3, 0x54, 0xbf, 0x0f, + 0xf7, 0xc4, 0xb1, 0xc2, 0xa9, 0x6e, 0x92, 0xc1, + 0xd8, 0xd8, 0xf0, 0xce, 0x00, 0x00, 0x00, 0x18, + 0x00, 0x00, 0x00, 0x00, 0x5e, 0xa7, 0xbc, 0x7c, + } + if _, err := firstVM.ParseBlock(secondAdvanceTimeBlkBytes); err != nil { + t.Fatal(err) + } + + firstVM.Shutdown() + + secondVM := &VM{ + SnowmanVM: &core.SnowmanVM{}, + chainManager: chains.MockManager{}, + } + + secondDefaultSubnet := validators.NewSet() + secondVM.validators = validators.NewManager() + secondVM.validators.PutValidatorSet(DefaultSubnetID, secondDefaultSubnet) + + secondVM.clock.Set(defaultGenesisTime) + secondCtx := defaultContext() + secondMsgChan := make(chan common.Message, 1) + if err := secondVM.Initialize(secondCtx, db, genesisBytes, secondMsgChan, nil); err != nil { + t.Fatal(err) + } + + if lastAccepted := secondVM.LastAccepted(); !genesisID.Equals(lastAccepted) { + t.Fatalf("Shouldn't have changed the genesis") + } +} + +// test restarting the node +func TestRestartFullyAccepted(t *testing.T) { + genesisAccounts := GenesisAccounts() + genesisValidators := GenesisCurrentValidators() + genesisChains := make([]*CreateChainTx, 0) + + genesisState := Genesis{ + Accounts: genesisAccounts, + Validators: genesisValidators, + Chains: genesisChains, + Timestamp: uint64(defaultGenesisTime.Unix()), + } + + genesisBytes, err := Codec.Marshal(genesisState) + if err != nil { + t.Fatal(err) + } + + db := memdb.New() + + firstVM := &VM{ + SnowmanVM: &core.SnowmanVM{}, + chainManager: chains.MockManager{}, + } + + firstDefaultSubnet := validators.NewSet() + firstVM.validators = validators.NewManager() + firstVM.validators.PutValidatorSet(DefaultSubnetID, firstDefaultSubnet) + + firstVM.clock.Set(defaultGenesisTime) + firstCtx := defaultContext() + firstMsgChan := make(chan common.Message, 1) + if err := firstVM.Initialize(firstCtx, db, genesisBytes, firstMsgChan, nil); err != nil { + t.Fatal(err) + } + + firstAdvanceTimeTx, err := firstVM.newAdvanceTimeTx(defaultGenesisTime.Add(time.Second)) + if err != nil { + t.Fatal(err) + } + firstAdvanceTimeBlk, err := firstVM.newProposalBlock(firstVM.Preferred(), firstAdvanceTimeTx) + if err != nil { + t.Fatal(err) + } + + firstVM.clock.Set(defaultGenesisTime.Add(2 * time.Second)) + if err := firstAdvanceTimeBlk.Verify(); err != nil { + t.Fatal(err) + } + + options := firstAdvanceTimeBlk.Options() + firstOption := options[0] + secondOption := options[1] + + if err := firstOption.Verify(); err != nil { + t.Fatal(err) + } + if err := secondOption.Verify(); err != nil { + t.Fatal(err) + } + + firstAdvanceTimeBlk.Accept() + firstOption.Accept() + secondOption.Reject() + + secondAdvanceTimeBlkBytes := []byte{ + 0x00, 0x00, 0x00, 0x00, 0xad, 0x64, 0x34, 0x49, + 0xa5, 0x05, 0xd8, 0xda, 0xc6, 0xd1, 0xb8, 0x2c, + 0x5c, 0xe6, 0x06, 0x81, 0xf3, 0x54, 0xbf, 0x0f, + 0xf7, 0xc4, 0xb1, 0xc2, 0xa9, 0x6e, 0x92, 0xc1, + 0xd8, 0xd8, 0xf0, 0xce, 0x00, 0x00, 0x00, 0x18, + 0x00, 0x00, 0x00, 0x00, 0x5e, 0xa7, 0xbc, 0x7c, + } + if _, err := firstVM.ParseBlock(secondAdvanceTimeBlkBytes); err != nil { + t.Fatal(err) + } + + firstVM.Shutdown() + + secondVM := &VM{ + SnowmanVM: &core.SnowmanVM{}, + chainManager: chains.MockManager{}, + } + + secondDefaultSubnet := validators.NewSet() + secondVM.validators = validators.NewManager() + secondVM.validators.PutValidatorSet(DefaultSubnetID, secondDefaultSubnet) + + secondVM.clock.Set(defaultGenesisTime) + secondCtx := defaultContext() + secondMsgChan := make(chan common.Message, 1) + if err := secondVM.Initialize(secondCtx, db, genesisBytes, secondMsgChan, nil); err != nil { + t.Fatal(err) + } + + if lastAccepted := secondVM.LastAccepted(); !firstOption.ID().Equals(lastAccepted) { + t.Fatalf("Should have changed the genesis") + } +} From 83c5bf39ae1c26056a6db1e24a8e048ae4b4853d Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Tue, 28 Apr 2020 15:53:36 -0400 Subject: [PATCH 57/61] Added handling for if bootstrapping partially accepted a block pair --- snow/engine/snowman/transitive.go | 20 ++- snow/engine/snowman/transitive_test.go | 18 +++ vms/components/core/block.go | 2 +- vms/components/core/snowman_vm.go | 8 +- vms/platformvm/proposal_block.go | 5 +- vms/platformvm/vm_test.go | 169 +++++++++++++++++++++++++ 6 files changed, 213 insertions(+), 9 deletions(-) diff --git a/snow/engine/snowman/transitive.go b/snow/engine/snowman/transitive.go index 947967a..9a827a6 100644 --- a/snow/engine/snowman/transitive.go +++ b/snow/engine/snowman/transitive.go @@ -45,10 +45,24 @@ func (t *Transitive) Initialize(config Config) { } func (t *Transitive) finishBootstrapping() { - tail := t.Config.VM.LastAccepted() - t.Config.VM.SetPreference(tail) - t.Consensus.Initialize(t.Config.Context, t.Params, tail) t.bootstrapped = true + tailID := t.Config.VM.LastAccepted() + t.Consensus.Initialize(t.Config.Context, t.Params, tailID) + + tail, err := t.Config.VM.GetBlock(tailID) + if err != nil { + t.Config.Context.Log.Error("Failed to get last accepted block due to: %s", err) + return + } + + switch blk := tail.(type) { + case OracleBlock: + for _, blk := range blk.Options() { + t.deliver(blk) + } + default: + t.Config.VM.SetPreference(tailID) + } } // Shutdown implements the Engine interface diff --git a/snow/engine/snowman/transitive_test.go b/snow/engine/snowman/transitive_test.go index 6000324..a1875d8 100644 --- a/snow/engine/snowman/transitive_test.go +++ b/snow/engine/snowman/transitive_test.go @@ -56,8 +56,17 @@ func setup(t *testing.T) (validators.Validator, validators.Set, *common.SenderTe te := &Transitive{} te.Initialize(config) + + vm.GetBlockF = func(blkID ids.ID) (snowman.Block, error) { + if !blkID.Equals(gBlk.ID()) { + t.Fatalf("Wrong block requested") + } + return gBlk, nil + } + te.finishBootstrapping() + vm.GetBlockF = nil vm.LastAcceptedF = nil sender.CantGetAcceptedFrontier = true @@ -369,8 +378,17 @@ func TestEngineMultipleQuery(t *testing.T) { te := &Transitive{} te.Initialize(config) + + vm.GetBlockF = func(blkID ids.ID) (snowman.Block, error) { + if !blkID.Equals(gBlk.ID()) { + t.Fatalf("Wrong block requested") + } + return gBlk, nil + } + te.finishBootstrapping() + vm.GetBlockF = nil vm.LastAcceptedF = nil sender.CantGetAcceptedFrontier = true diff --git a/vms/components/core/block.go b/vms/components/core/block.go index 0690a0d..cfd9d36 100644 --- a/vms/components/core/block.go +++ b/vms/components/core/block.go @@ -57,7 +57,7 @@ func (b *Block) Accept() { b.SetStatus(choices.Accepted) // Change state of this block b.VM.State.PutStatus(b.VM.DB, b.ID(), choices.Accepted) // Persist data b.VM.State.PutLastAccepted(b.VM.DB, b.ID()) - b.VM.lastAccepted = b.ID() // Change state of VM + b.VM.LastAcceptedID = b.ID() // Change state of VM } // Reject sets this block's status to Rejected and saves the status in state diff --git a/vms/components/core/snowman_vm.go b/vms/components/core/snowman_vm.go index f710edd..6da28dd 100644 --- a/vms/components/core/snowman_vm.go +++ b/vms/components/core/snowman_vm.go @@ -45,7 +45,7 @@ type SnowmanVM struct { preferred ids.ID // ID of the last accepted block - lastAccepted ids.ID + LastAcceptedID ids.ID // unmarshals bytes to a block unmarshalBlockFunc func([]byte) (snowman.Block, error) @@ -61,7 +61,7 @@ func (svm *SnowmanVM) SetPreference(ID ids.ID) { svm.preferred = ID } func (svm *SnowmanVM) Preferred() ids.ID { return svm.preferred } // LastAccepted returns the block most recently accepted -func (svm *SnowmanVM) LastAccepted() ids.ID { return svm.lastAccepted } +func (svm *SnowmanVM) LastAccepted() ids.ID { return svm.LastAcceptedID } // ParseBlock parses [bytes] to a block func (svm *SnowmanVM) ParseBlock(bytes []byte) (snowman.Block, error) { @@ -161,10 +161,10 @@ func (svm *SnowmanVM) Initialize( } if svm.DBInitialized() { - if svm.lastAccepted, err = svm.State.GetLastAccepted(svm.DB); err != nil { + if svm.LastAcceptedID, err = svm.State.GetLastAccepted(svm.DB); err != nil { return err } - svm.preferred = svm.lastAccepted + svm.preferred = svm.LastAcceptedID } return nil diff --git a/vms/platformvm/proposal_block.go b/vms/platformvm/proposal_block.go index 5ddfe3f..ac62303 100644 --- a/vms/platformvm/proposal_block.go +++ b/vms/platformvm/proposal_block.go @@ -43,7 +43,10 @@ type ProposalBlock struct { } // Accept implements the snowman.Block interface -func (pb *ProposalBlock) Accept() { pb.SetStatus(choices.Accepted) } +func (pb *ProposalBlock) Accept() { + pb.SetStatus(choices.Accepted) + pb.VM.LastAcceptedID = pb.ID() +} // Initialize this block. // Sets [pb.vm] to [vm] and populates non-serialized fields diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 9c9e467..e30dd8a 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -10,13 +10,22 @@ import ( "testing" "time" + "github.com/prometheus/client_golang/prometheus" + "github.com/ava-labs/gecko/chains" "github.com/ava-labs/gecko/chains/atomic" "github.com/ava-labs/gecko/database/memdb" + "github.com/ava-labs/gecko/database/prefixdb" "github.com/ava-labs/gecko/ids" "github.com/ava-labs/gecko/snow" "github.com/ava-labs/gecko/snow/choices" + "github.com/ava-labs/gecko/snow/consensus/snowball" "github.com/ava-labs/gecko/snow/engine/common" + "github.com/ava-labs/gecko/snow/engine/common/queue" + "github.com/ava-labs/gecko/snow/networking/handler" + "github.com/ava-labs/gecko/snow/networking/router" + "github.com/ava-labs/gecko/snow/networking/sender" + "github.com/ava-labs/gecko/snow/networking/timeout" "github.com/ava-labs/gecko/snow/validators" "github.com/ava-labs/gecko/utils/crypto" "github.com/ava-labs/gecko/utils/formatting" @@ -25,6 +34,9 @@ import ( "github.com/ava-labs/gecko/vms/components/core" "github.com/ava-labs/gecko/vms/secp256k1fx" "github.com/ava-labs/gecko/vms/timestampvm" + + smcon "github.com/ava-labs/gecko/snow/consensus/snowman" + smeng "github.com/ava-labs/gecko/snow/engine/snowman" ) var ( @@ -1427,3 +1439,160 @@ func TestRestartFullyAccepted(t *testing.T) { t.Fatalf("Should have changed the genesis") } } + +// test bootstrapping the node +func TestBootstrapPartiallyAccepted(t *testing.T) { + genesisAccounts := GenesisAccounts() + genesisValidators := GenesisCurrentValidators() + genesisChains := make([]*CreateChainTx, 0) + + genesisState := Genesis{ + Accounts: genesisAccounts, + Validators: genesisValidators, + Chains: genesisChains, + Timestamp: uint64(defaultGenesisTime.Unix()), + } + + genesisBytes, err := Codec.Marshal(genesisState) + if err != nil { + t.Fatal(err) + } + + db := memdb.New() + vmDB := prefixdb.New([]byte("vm"), db) + bootstrappingDB := prefixdb.New([]byte("bootstrapping"), db) + + blocked, err := queue.New(bootstrappingDB) + if err != nil { + t.Fatal(err) + } + + vm := &VM{ + SnowmanVM: &core.SnowmanVM{}, + chainManager: chains.MockManager{}, + } + defer vm.Shutdown() + + defaultSubnet := validators.NewSet() + vm.validators = validators.NewManager() + vm.validators.PutValidatorSet(DefaultSubnetID, defaultSubnet) + + vm.clock.Set(defaultGenesisTime) + ctx := defaultContext() + msgChan := make(chan common.Message, 1) + + ctx.Lock.Lock() + if err := vm.Initialize(ctx, vmDB, genesisBytes, msgChan, nil); err != nil { + t.Fatal(err) + } + + genesisID := vm.Preferred() + + advanceTimeTx, err := vm.newAdvanceTimeTx(defaultGenesisTime.Add(time.Second)) + if err != nil { + t.Fatal(err) + } + advanceTimeBlk, err := vm.newProposalBlock(vm.Preferred(), advanceTimeTx) + if err != nil { + t.Fatal(err) + } + advanceTimeBlkID := advanceTimeBlk.ID() + advanceTimeBlkBytes := advanceTimeBlk.Bytes() + + advanceTimePreference := advanceTimeBlk.Options()[0] + + vdrs := validators.NewSet() + vdrs.Add(validators.NewValidator(ctx.NodeID, 1)) + beacons := vdrs + + timeoutManager := timeout.Manager{} + timeoutManager.Initialize(2 * time.Second) + go timeoutManager.Dispatch() + + router := &router.ChainRouter{} + router.Initialize(logging.NoLog{}, &timeoutManager) + + externalSender := &sender.ExternalSenderTest{T: t} + externalSender.Default(true) + + // Passes messages from the consensus engine to the network + sender := sender.Sender{} + + sender.Initialize(ctx, externalSender, router, &timeoutManager) + + // The engine handles consensus + engine := smeng.Transitive{} + engine.Initialize(smeng.Config{ + BootstrapConfig: smeng.BootstrapConfig{ + Config: common.Config{ + Context: ctx, + Validators: vdrs, + Beacons: beacons, + Alpha: uint64(beacons.Len()/2 + 1), + Sender: &sender, + }, + Blocked: blocked, + VM: vm, + }, + Params: snowball.Parameters{ + Metrics: prometheus.NewRegistry(), + K: 1, + Alpha: 1, + BetaVirtuous: 20, + BetaRogue: 20, + ConcurrentRepolls: 1, + }, + Consensus: &smcon.Topological{}, + }) + + // Asynchronously passes messages from the network to the consensus engine + handler := &handler.Handler{} + handler.Initialize(&engine, msgChan, 1000) + + // Allow incoming messages to be routed to the new chain + router.AddChain(handler) + go ctx.Log.RecoverAndPanic(handler.Dispatch) + + reqID := new(uint32) + externalSender.GetAcceptedFrontierF = func(_ ids.ShortSet, _ ids.ID, requestID uint32) { + *reqID = requestID + } + + engine.Startup() + + externalSender.GetAcceptedFrontierF = nil + externalSender.GetAcceptedF = func(_ ids.ShortSet, _ ids.ID, requestID uint32, _ ids.Set) { + *reqID = requestID + } + + frontier := ids.Set{} + frontier.Add(advanceTimeBlkID) + engine.AcceptedFrontier(ctx.NodeID, *reqID, frontier) + + externalSender.GetAcceptedF = nil + externalSender.GetF = func(_ ids.ShortID, _ ids.ID, requestID uint32, containerID ids.ID) { + *reqID = requestID + if !containerID.Equals(advanceTimeBlkID) { + t.Fatalf("wrong block requested") + } + } + + engine.Accepted(ctx.NodeID, *reqID, frontier) + + externalSender.GetF = nil + externalSender.CantPushQuery = false + + engine.Put(ctx.NodeID, *reqID, advanceTimeBlkID, advanceTimeBlkBytes) + + externalSender.CantPushQuery = true + + if pref := vm.Preferred(); !pref.Equals(advanceTimePreference.ID()) { + t.Fatalf("wrong preference reported after bootstrapping to proposal block\nPreferred: %s\nExpected: %s\nGenesis: %s", + pref, + advanceTimePreference.ID(), + genesisID) + } + ctx.Lock.Unlock() + + router.Shutdown() +} From e25e0356baba338c4f5758c41d9711d1677d5673 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Tue, 28 Apr 2020 16:09:47 -0400 Subject: [PATCH 58/61] Added multiple inventories + bumped patch version --- networking/handshake_handlers.go | 2 +- .../{inventory.yml => cascade-inventory.yml} | 0 scripts/ansible/restart_playbook.yml | 2 +- scripts/ansible/test-inventory.yml | 95 +++++++++++++++++++ scripts/ansible/update_playbook.yml | 2 +- 5 files changed, 98 insertions(+), 3 deletions(-) rename scripts/ansible/{inventory.yml => cascade-inventory.yml} (100%) create mode 100755 scripts/ansible/test-inventory.yml diff --git a/networking/handshake_handlers.go b/networking/handshake_handlers.go index 9e0c9cf..3ed5e1a 100644 --- a/networking/handshake_handlers.go +++ b/networking/handshake_handlers.go @@ -69,7 +69,7 @@ var ( VersionSeparator = "." MajorVersion = 0 MinorVersion = 1 - PatchVersion = 0 + PatchVersion = 1 ClientVersion = fmt.Sprintf("%s%d%s%d%s%d", VersionPrefix, MajorVersion, diff --git a/scripts/ansible/inventory.yml b/scripts/ansible/cascade-inventory.yml similarity index 100% rename from scripts/ansible/inventory.yml rename to scripts/ansible/cascade-inventory.yml diff --git a/scripts/ansible/restart_playbook.yml b/scripts/ansible/restart_playbook.yml index deec014..93b0bad 100755 --- a/scripts/ansible/restart_playbook.yml +++ b/scripts/ansible/restart_playbook.yml @@ -8,7 +8,7 @@ ava_binary: ~/go/src/github.com/ava-labs/gecko/build/ava repo_folder: ~/go/src/github.com/ava-labs/gecko repo_name: ava-labs/gecko-internal - repo_branch: retry-connections + repo_branch: platformvm-proposal-accept tasks: - name: Kill Node command: killall ava diff --git a/scripts/ansible/test-inventory.yml b/scripts/ansible/test-inventory.yml new file mode 100755 index 0000000..220a8f4 --- /dev/null +++ b/scripts/ansible/test-inventory.yml @@ -0,0 +1,95 @@ +borealis_bootstrap: + hosts: + bootstrap1: + ansible_host: 3.84.129.247 + staking_tls_key_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker1.key" + staking_tls_cert_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker1.crt" + vars: + ansible_connection: ssh + ansible_user: ubuntu + + network_id: "local" + api_admin_enabled: true + api_keystore_enabled: true + api_metrics_enabled: true + ava_tx_fee: 0 + assertions_enabled: true + signature_verification_enabled: true + db_enabled: true + db_dir: "/home/ubuntu/db" + http_port: 21000 + http_tls_enabled: false + http_tls_key_file: "" + http_tls_cert_file: "" + bootstrap_ips: "" + bootstrap_ids: "" + staking_port: 21001 + staking_tls_enabled: true + staking_tls_key_file: "/home/ubuntu/keys/staker.key" + staking_tls_cert_file: "/home/ubuntu/keys/staker.crt" + plugin_dir: "/home/ubuntu/go/src/github.com/ava-labs/gecko/build/plugins" + log_dir: "/home/ubuntu/.gecko" + log_level: debug + snow_sample_size: 3 + snow_quorum_size: 2 + snow_virtuous_commit_threshold: 20 + snow_rogue_commit_threshold: 30 + snow_avalanche_num_parents: 5 + snow_avalanche_batch_size: 30 + api_ipcs_enabled: false + xput_server_enabled: false + xput_server_port: 21002 + +borealis_node: + hosts: + node1: + ansible_host: 35.153.99.244 + staking_tls_key_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker2.key" + staking_tls_cert_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker2.crt" + node2: + ansible_host: 34.201.137.119 + staking_tls_key_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker3.key" + staking_tls_cert_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker3.crt" + node3: + ansible_host: 54.146.1.110 + staking_tls_key_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker4.key" + staking_tls_cert_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker4.crt" + node4: + ansible_host: 54.91.255.231 + staking_tls_key_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker5.key" + staking_tls_cert_file: "/home/ubuntu/go/src/github.com/ava-labs/gecko/keys/local/staker5.crt" + vars: + ansible_connection: ssh + ansible_user: ubuntu + + network_id: "local" + api_admin_enabled: true + api_keystore_enabled: true + api_metrics_enabled: true + ava_tx_fee: 0 + assertions_enabled: true + signature_verification_enabled: true + db_enabled: true + db_dir: "/home/ubuntu/db" + http_port: 21000 + http_tls_enabled: false + http_tls_key_file: "" + http_tls_cert_file: "" + bootstrap_ips: "3.84.129.247:21001" + bootstrap_ids: "7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg" + staking_port: 21001 + staking_tls_enabled: true + staking_tls_key_file: "/home/ubuntu/keys/staker.key" + staking_tls_cert_file: "/home/ubuntu/keys/staker.crt" + plugin_dir: "/home/ubuntu/go/src/github.com/ava-labs/gecko/build/plugins" + log_dir: "/home/ubuntu/.gecko" + log_level: debug + snow_sample_size: 3 + snow_quorum_size: 2 + snow_virtuous_commit_threshold: 20 + snow_rogue_commit_threshold: 30 + snow_avalanche_num_parents: 5 + snow_avalanche_batch_size: 30 + api_ipcs_enabled: false + xput_server_enabled: false + xput_server_port: 21002 diff --git a/scripts/ansible/update_playbook.yml b/scripts/ansible/update_playbook.yml index e66dc17..c31cf89 100755 --- a/scripts/ansible/update_playbook.yml +++ b/scripts/ansible/update_playbook.yml @@ -8,7 +8,7 @@ ava_binary: ~/go/src/github.com/ava-labs/gecko/build/ava repo_folder: ~/go/src/github.com/ava-labs/gecko repo_name: ava-labs/gecko-internal - repo_branch: retry-connections + repo_branch: platformvm-proposal-accept tasks: - name: Kill Node command: killall ava From 52bbfb669b346b1fe5110a4e9629562f26df587d Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Tue, 28 Apr 2020 16:10:47 -0400 Subject: [PATCH 59/61] Bump db version --- main/params.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/params.go b/main/params.go index 68b63c4..f4c0012 100644 --- a/main/params.go +++ b/main/params.go @@ -27,7 +27,7 @@ import ( ) const ( - dbVersion = "v0.1.0" + dbVersion = "v0.1.1" ) // Results of parsing the CLI From acfa6e4a68bbec08f173ef885919ed36e61db0a0 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Tue, 28 Apr 2020 16:30:48 -0400 Subject: [PATCH 60/61] changed version bump from patch to minor to remove accidential replay attacks --- main/params.go | 2 +- networking/handshake_handlers.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main/params.go b/main/params.go index f4c0012..48444a7 100644 --- a/main/params.go +++ b/main/params.go @@ -27,7 +27,7 @@ import ( ) const ( - dbVersion = "v0.1.1" + dbVersion = "v0.2.0" ) // Results of parsing the CLI diff --git a/networking/handshake_handlers.go b/networking/handshake_handlers.go index 3ed5e1a..b605935 100644 --- a/networking/handshake_handlers.go +++ b/networking/handshake_handlers.go @@ -68,8 +68,8 @@ var ( VersionPrefix = "avalanche/" VersionSeparator = "." MajorVersion = 0 - MinorVersion = 1 - PatchVersion = 1 + MinorVersion = 2 + PatchVersion = 0 ClientVersion = fmt.Sprintf("%s%d%s%d%s%d", VersionPrefix, MajorVersion, From 197521af51ef00e07539318a8b898816a39b4dfc Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 29 Apr 2020 13:44:25 -0400 Subject: [PATCH 61/61] change default db dir to ~/.gecko/db --- main/params.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main/params.go b/main/params.go index 48444a7..a216720 100644 --- a/main/params.go +++ b/main/params.go @@ -24,10 +24,12 @@ import ( "github.com/ava-labs/gecko/utils/hashing" "github.com/ava-labs/gecko/utils/logging" "github.com/ava-labs/gecko/utils/wrappers" + "github.com/mitchellh/go-homedir" ) const ( - dbVersion = "v0.2.0" + dbVersion = "v0.2.0" + defaultDbDir = "~/.gecko/db" ) // Results of parsing the CLI @@ -80,7 +82,7 @@ func init() { // Database: db := fs.Bool("db-enabled", true, "Turn on persistent storage") - dbDir := fs.String("db-dir", "db", "Database directory for Ava state") + dbDir := fs.String("db-dir", defaultDbDir, "Database directory for Ava state") // IP: consensusIP := fs.String("public-ip", "", "Public IP of this node") @@ -147,6 +149,11 @@ func init() { // DB: if *db && err == nil { // TODO: Add better params here + if *dbDir == defaultDbDir { + if *dbDir, err = homedir.Expand(defaultDbDir); err != nil { + errs.Add(fmt.Errorf("couldn't resolve default db path: %v", err)) + } + } dbPath := path.Join(*dbDir, genesis.NetworkName(Config.NetworkID), dbVersion) db, err := leveldb.New(dbPath, 0, 0, 0) Config.DB = db