Skip to content

Commit

Permalink
worker/registration: fix waiting for deregister event
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Apr 12, 2022
1 parent da924ac commit 8baf090
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions .changelog/4662.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix waiting for deregister event on `RequestShutdown`
3 changes: 3 additions & 0 deletions go/oasis-node/cmd/common/genesis/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ func NewAppendableStakingState() (*AppendableStakingState, error) {
st := &AppendableStakingState{
State: staking.Genesis{
Ledger: make(map[staking.Address]*staking.Account),
Parameters: staking.ConsensusParameters{
DebondingInterval: 1, // Minimum valid debonding interval.
},
},
}
if err := st.setDefaultFeeSplit(); err != nil {
Expand Down
20 changes: 20 additions & 0 deletions go/oasis-test-runner/scenario/e2e/runtime/keymanager_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"path/filepath"
"time"

"github.com/oasisprotocol/oasis-core/go/common"
"github.com/oasisprotocol/oasis-core/go/common/cbor"
Expand Down Expand Up @@ -283,13 +284,32 @@ func (sc *kmUpgradeImpl) Run(childEnv *env.Env) error {
return err
}

nodeCh, nodeSub, err := sc.Net.Controller().Registry.WatchNodes(ctx)
if err != nil {
return fmt.Errorf("failed to watch nodes: %w", err)
}
defer nodeSub.Close()

// Shutdown old keymanager and make sure it deregisters.
sc.Logger.Info("shutting down old keymanager")
oldKm := sc.Net.Keymanagers()[0]
if err := oldKm.RequestShutdown(ctx, true); err != nil {
return fmt.Errorf("failed to request shutdown: %w", err)
}

// Ensure keymanager deregisters.
OUTER:
for {
select {
case ev := <-nodeCh:
if !ev.IsRegistration && ev.Node.ID.Equal(oldKm.NodeID) {
break OUTER
}
case <-time.After(10 * time.Second):
return fmt.Errorf("failed to wait for keymanager to de-register")
}
}

// Run client again.
sc.Logger.Info("starting a second client to check if key manager works")
newTestClient := sc.testClient.Clone().(*KeyValueEncTestClient)
Expand Down
3 changes: 0 additions & 3 deletions go/worker/registration/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,6 @@ func (w *Worker) doNodeRegistration() {

case <-w.stopCh:
return

case <-w.stopRegCh:
return
}
}
}
Expand Down

0 comments on commit 8baf090

Please sign in to comment.