From 91de93a26a3745c63e81adbe86890a8b24a44f2f Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Mon, 18 May 2020 11:22:15 -0400 Subject: [PATCH 1/6] If staking is disabled, always attempt to reconnect to a peer --- 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 d82df74..554f4fb 100644 --- a/networking/handshake_handlers.go +++ b/networking/handshake_handlers.go @@ -515,7 +515,7 @@ func (nm *Handshake) disconnectedFromPeer(peer salticidae.PeerID) { nm.connections.Remove(peer, cert) nm.numPeers.Set(float64(nm.connections.Len())) - if nm.vdrs.Contains(cert) { + if !nm.enableStaking || nm.vdrs.Contains(cert) { nm.reconnectTimeout.Put(peerID, func() { nm.pending.Remove(peer, cert) nm.connections.Remove(peer, cert) From 503c90e8399f6fc2e73f79f1768748d238984e7c Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Mon, 18 May 2020 11:33:58 -0400 Subject: [PATCH 2/6] Clean up the acceptance of atomic blocks --- vms/platformvm/atomic_block.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/vms/platformvm/atomic_block.go b/vms/platformvm/atomic_block.go index 20c2892..3293094 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 { - SingleDecisionBlock `serialize:"true"` + CommonDecisionBlock `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.SingleDecisionBlock.initialize(vm, bytes); err != nil { + if err := ab.CommonDecisionBlock.initialize(vm, bytes); err != nil { return err } return ab.Tx.initialize(vm) @@ -123,9 +123,6 @@ func (ab *AtomicBlock) Accept() { ab.onAcceptFunc() } - parent := ab.parentBlock() - // remove this block and its parent from memory - parent.free() ab.free() } @@ -133,11 +130,9 @@ func (ab *AtomicBlock) Accept() { // decision block, has ID [parentID]. func (vm *VM) newAtomicBlock(parentID ids.ID, tx AtomicTx) (*AtomicBlock, error) { ab := &AtomicBlock{ - SingleDecisionBlock: SingleDecisionBlock{CommonDecisionBlock: CommonDecisionBlock{ - CommonBlock: CommonBlock{ - Block: core.NewBlock(parentID), - vm: vm, - }, + CommonDecisionBlock: CommonDecisionBlock{CommonBlock: CommonBlock{ + Block: core.NewBlock(parentID), + vm: vm, }}, Tx: tx, } From e9218c733b402561a29eee49aa82a85e697a9501 Mon Sep 17 00:00:00 2001 From: Collin Montag Date: Mon, 18 May 2020 12:18:48 -0400 Subject: [PATCH 3/6] ks importuser password check --- api/keystore/service.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/keystore/service.go b/api/keystore/service.go index fe1b349..ec497b5 100644 --- a/api/keystore/service.go +++ b/api/keystore/service.go @@ -266,8 +266,12 @@ func (ks *Keystore) ImportUser(r *http.Request, args *ImportUserArgs, reply *Imp ks.log.Verbo("ImportUser called for %s", args.Username) - if usr, err := ks.getUser(args.Username); err == nil || usr != nil { + usr, err := ks.getUser(args.Username) + switch { + case err == nil || usr != nil: return fmt.Errorf("user already exists: %s", args.Username) + case !usr.CheckPassword(args.Password): + return fmt.Errorf("incorrect password for user %q", args.Username) } userData := UserDB{} From b2a85ccecdcb1a65f1d8a0d8cc1f62603b01b550 Mon Sep 17 00:00:00 2001 From: Collin Montag Date: Mon, 18 May 2020 14:19:15 -0400 Subject: [PATCH 4/6] ks importuser fix --- api/keystore/service.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/api/keystore/service.go b/api/keystore/service.go index ec497b5..bba5576 100644 --- a/api/keystore/service.go +++ b/api/keystore/service.go @@ -266,18 +266,17 @@ func (ks *Keystore) ImportUser(r *http.Request, args *ImportUserArgs, reply *Imp ks.log.Verbo("ImportUser called for %s", args.Username) - usr, err := ks.getUser(args.Username) - switch { - case err == nil || usr != nil: + if usr, err := ks.getUser(args.Username); err == nil || usr != nil { return fmt.Errorf("user already exists: %s", args.Username) - case !usr.CheckPassword(args.Password): - return fmt.Errorf("incorrect password for user %q", args.Username) } userData := UserDB{} if err := ks.codec.Unmarshal(args.User.Bytes, &userData); err != nil { return err } + if !userData.User.CheckPassword(args.Password) { + return fmt.Errorf("incorrect password for %s", args.Username) + } usrBytes, err := ks.codec.Marshal(&userData.User) if err != nil { From f655592a1c1ac35c3885bc01faa68b5fb3736ef7 Mon Sep 17 00:00:00 2001 From: Collin Montag Date: Mon, 18 May 2020 14:36:37 -0400 Subject: [PATCH 5/6] standard password error --- api/keystore/service.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/keystore/service.go b/api/keystore/service.go index bba5576..5575083 100644 --- a/api/keystore/service.go +++ b/api/keystore/service.go @@ -218,7 +218,7 @@ func (ks *Keystore) ExportUser(_ *http.Request, args *ExportUserArgs, reply *Exp return err } if !usr.CheckPassword(args.Password) { - return fmt.Errorf("incorrect password for %s", args.Username) + return fmt.Errorf("incorrect password for user %q", args.Username) } userDB := prefixdb.New([]byte(args.Username), ks.bcDB) @@ -275,7 +275,7 @@ func (ks *Keystore) ImportUser(r *http.Request, args *ImportUserArgs, reply *Imp return err } if !userData.User.CheckPassword(args.Password) { - return fmt.Errorf("incorrect password for %s", args.Username) + return fmt.Errorf("incorrect password for user %q", args.Username) } usrBytes, err := ks.codec.Marshal(&userData.User) @@ -386,7 +386,7 @@ func (ks *Keystore) GetDatabase(bID ids.ID, username, password string) (database return nil, err } if !usr.CheckPassword(password) { - return nil, fmt.Errorf("incorrect password for user '%s'", username) + return nil, fmt.Errorf("incorrect password for user %q", username) } userDB := prefixdb.New([]byte(username), ks.bcDB) From e2ba60d3aceb0dbc308dfd7ddbdb15a7e6a3503b Mon Sep 17 00:00:00 2001 From: Collin Montag Date: Mon, 18 May 2020 15:07:23 -0400 Subject: [PATCH 6/6] added importuser test --- api/keystore/service_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/api/keystore/service_test.go b/api/keystore/service_test.go index 75b7166..b4c805d 100644 --- a/api/keystore/service_test.go +++ b/api/keystore/service_test.go @@ -255,6 +255,17 @@ func TestServiceExportImport(t *testing.T) { newKS := Keystore{} newKS.Initialize(logging.NoLog{}, memdb.New()) + { + reply := ImportUserReply{} + if err := newKS.ImportUser(nil, &ImportUserArgs{ + Username: "bob", + Password: "", + User: exportReply.User, + }, &reply); err == nil { + t.Fatal("Should have errored due to incorrect password") + } + } + { reply := ImportUserReply{} if err := newKS.ImportUser(nil, &ImportUserArgs{