Skip to content

Commit

Permalink
go/oasis-test-runner: Test dynamic KM runtime registration
Browse files Browse the repository at this point in the history
  • Loading branch information
abukosek committed Apr 20, 2020
1 parent 9bf11b4 commit de723ec
Show file tree
Hide file tree
Showing 11 changed files with 360 additions and 113 deletions.
Empty file added .changelog/2840.trivial.md
Empty file.
3 changes: 2 additions & 1 deletion go/consensus/tendermint/apps/keymanager/keymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
stakingState "github.com/oasislabs/oasis-core/go/consensus/tendermint/apps/staking/state"
epochtime "github.com/oasislabs/oasis-core/go/epochtime/api"
"github.com/oasislabs/oasis-core/go/keymanager/api"
keymanager "github.com/oasislabs/oasis-core/go/keymanager/api"
registry "github.com/oasislabs/oasis-core/go/registry/api"
)

Expand All @@ -37,7 +38,7 @@ func (app *keymanagerApplication) ID() uint8 {
}

func (app *keymanagerApplication) Methods() []transaction.MethodName {
return nil
return keymanager.Methods
}

func (app *keymanagerApplication) Blessed() bool {
Expand Down
10 changes: 9 additions & 1 deletion go/consensus/tendermint/apps/keymanager/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ func (app *keymanagerApplication) updatePolicy(

// Get the existing policy document, if one exists.
oldStatus, err := state.Status(ctx, rt.ID)
if err != nil {
switch err {
case nil:
case api.ErrNoSuchStatus:
// This must be a new key manager runtime.
oldStatus = &api.Status{
ID: rt.ID,
}
default:
return err
}

Expand Down Expand Up @@ -68,6 +75,7 @@ func (app *keymanagerApplication) updatePolicy(
// will get updated.
nodes, _ := regState.Nodes(ctx)
registry.SortNodeList(nodes)
oldStatus.Policy = sigPol
newStatus := app.generateStatus(ctx, rt, oldStatus, nodes)
if err := state.SetStatus(ctx, newStatus); err != nil {
panic(fmt.Errorf("failed to set keymanager status: %w", err))
Expand Down
19 changes: 15 additions & 4 deletions go/consensus/tendermint/keymanager/keymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/eapache/channels"
"github.com/pkg/errors"
abcitypes "github.com/tendermint/tendermint/abci/types"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/oasislabs/oasis-core/go/common"
Expand Down Expand Up @@ -88,17 +89,27 @@ func (tb *tendermintBackend) worker(ctx context.Context) {

switch ev := event.(type) {
case tmtypes.EventDataNewBlock:
tb.onEventDataNewBlock(ev)
tb.onEventDataNewBlock(ctx, ev)
case tmtypes.EventDataTx:
tb.onEventDataTx(ctx, ev)
default:
}
}
}

func (tb *tendermintBackend) onEventDataNewBlock(ev tmtypes.EventDataNewBlock) {
events := ev.ResultBeginBlock.GetEvents()
func (tb *tendermintBackend) onEventDataNewBlock(ctx context.Context, ev tmtypes.EventDataNewBlock) {
events := append([]abcitypes.Event{}, ev.ResultBeginBlock.GetEvents()...)
events = append(events, ev.ResultEndBlock.GetEvents()...)

for _, tmEv := range events {
tb.onABCIEvents(ctx, events)
}

func (tb *tendermintBackend) onEventDataTx(ctx context.Context, tx tmtypes.EventDataTx) {
tb.onABCIEvents(ctx, tx.Result.Events)
}

func (tb *tendermintBackend) onABCIEvents(ctx context.Context, tmEvents []abcitypes.Event) {
for _, tmEv := range tmEvents {
if tmEv.GetType() != app.EventType {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion go/keymanager/api/policy_sgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type EnclavePolicySGX struct {
//
// TODO: This could be made more sophisticated and seggregate based on
// contract ID as well, but for now punt on the added complexity.
MayQuery map[signature.PublicKey][]sgx.EnclaveIdentity `json:"may_query"`
MayQuery map[common.Namespace][]sgx.EnclaveIdentity `json:"may_query"`

// MayReplicate is the vector of enclave IDs that may retrieve the master
// secret (Note: Each enclave ID may always implicitly replicate from other
Expand Down
Loading

0 comments on commit de723ec

Please sign in to comment.