Skip to content

Commit

Permalink
Merge pull request #472 from quorumcontrol/fix/default-client-ownersh…
Browse files Browse the repository at this point in the history
…ip-validator

make isOwner usable inside Client
  • Loading branch information
Brandon Westcott authored Apr 20, 2020
2 parents bd5435a + 9e99e04 commit 9215312
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 8 additions & 2 deletions sdk/gossip/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func NewWithConfig(ctx context.Context, config *Config) (*Client, error) {
if err != nil {
return nil, err
}
return &Client{
cli := &Client{
Group: config.Group,
logger: config.Logger,
pubsub: config.Pubsub,
Expand All @@ -96,7 +96,13 @@ func NewWithConfig(ctx context.Context, config *Config) (*Client, error) {
transactors: config.Transactors,
subscriber: config.subscriber,
onStartHooks: config.OnStartHooks,
}, nil
}

if cli.Group.DagGetter == nil {
cli.Group.DagGetter = types.NewClientDagGetter(cli)
}

return cli, nil
}

func (c *Client) DagStore() nodestore.DagStore {
Expand Down
2 changes: 0 additions & 2 deletions sdk/gossip/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ func newClient(ctx context.Context, group *types.NotaryGroup, bootAddrs []string
return nil, err
}

group.DagGetter = types.NewClientDagGetter(cli)

return cli, nil
}

Expand Down
10 changes: 3 additions & 7 deletions sdk/gossip/types/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/ipfs/go-cid"

"github.com/quorumcontrol/chaintree/graftabledag"
"github.com/quorumcontrol/chaintree/typecaster"

"github.com/quorumcontrol/tupelo/sdk/consensus"
Expand Down Expand Up @@ -184,24 +183,21 @@ func HasBurnGenerator(ctx context.Context, ng *NotaryGroup) (chaintree.BlockVali
// of this or any owning chaintree, or any other path that resolves to owner key addrs) has signed
// this block.
func IsOwnerGenerator(ctx context.Context, ng *NotaryGroup) (chaintree.BlockValidatorFunc, error) {
dagGetter := ng.DagGetter

var isOwnerValidator chaintree.BlockValidatorFunc = func(tree *dag.Dag, blockWithHeaders *chaintree.BlockWithHeaders) (bool, chaintree.CodedError) {
return isOwner(ctx, dagGetter, tree, blockWithHeaders)
return isOwner(ctx, ng, tree, blockWithHeaders)
}

return isOwnerValidator, nil
}

func isOwner(ctx context.Context, dagGetter graftabledag.DagGetter, tree *dag.Dag, blockWithHeaders *chaintree.BlockWithHeaders) (bool, chaintree.CodedError) {
func isOwner(ctx context.Context, ng *NotaryGroup, tree *dag.Dag, blockWithHeaders *chaintree.BlockWithHeaders) (bool, chaintree.CodedError) {
headers := &consensus.StandardHeaders{}

err := typecaster.ToType(blockWithHeaders.Headers, headers)
if err != nil {
return false, &consensus.ErrorCode{Memo: fmt.Sprintf("error: %v", err), Code: consensus.ErrUnknown}
}

gro, err := NewGraftedOwnership(tree, dagGetter)
gro, err := NewGraftedOwnership(tree, ng.DagGetter)
if err != nil {
return false, &consensus.ErrorCode{Memo: fmt.Sprintf("error creating GraftedOwnership: %v", err), Code: consensus.ErrUnknown}
}
Expand Down

0 comments on commit 9215312

Please sign in to comment.