Skip to content

Commit

Permalink
Merge 5df26e0 into 6509bf5
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilthoniel committed May 4, 2020
2 parents 6509bf5 + 5df26e0 commit 92e3aa0
Show file tree
Hide file tree
Showing 58 changed files with 3,374 additions and 2,596 deletions.
5 changes: 3 additions & 2 deletions blockchain/skipchain/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,14 @@ func (rand fakeRandGenerator) Read(buffer []byte) (int, error) {
}

type fakeGovernance struct {
viewchange.Governance
authority fake.CollectiveAuthority
}

func (gov fakeGovernance) GetAuthority(index uint64) (viewchange.EvolvableAuthority, error) {
return gov.authority, nil
}

func (gov fakeGovernance) GetChangeSet(uint64) viewchange.ChangeSet {
return viewchange.ChangeSet{}
func (gov fakeGovernance) GetChangeSet(uint64) (viewchange.ChangeSet, error) {
return viewchange.ChangeSet{}, nil
}
13 changes: 11 additions & 2 deletions consensus/cosipbft/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ func (a pbftActor) Propose(p consensus.Proposal) error {
return nil
}

changeset := a.governance.GetChangeSet(p.GetIndex() - 1)
changeset, err := a.governance.GetChangeSet(p.GetIndex() - 1)
if err != nil {
return xerrors.Errorf("couldn't get change set: %v", err)
}

changeset.Leader = leader

ctx := context.Background()
Expand Down Expand Up @@ -249,10 +253,15 @@ func (h handler) Hash(addr mino.Address, in proto.Message) (Digest, error) {
last.GetTo(), proposal.GetPreviousHash())
}

changeset, err := h.governance.GetChangeSet(proposal.GetIndex() - 1)
if err != nil {
return nil, xerrors.Errorf("couldn't get change set: %v", err)
}

forwardLink := forwardLink{
from: proposal.GetPreviousHash(),
to: proposal.GetHash(),
changeset: h.governance.GetChangeSet(proposal.GetIndex() - 1),
changeset: changeset,
}

leader := h.viewchange.Verify(proposal, authority)
Expand Down
4 changes: 2 additions & 2 deletions consensus/cosipbft/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,8 @@ func (gov fakeGovernance) GetAuthority(index uint64) (viewchange.EvolvableAuthor
return gov.authority, gov.err
}

func (gov fakeGovernance) GetChangeSet(uint64) viewchange.ChangeSet {
return gov.changeset
func (gov fakeGovernance) GetChangeSet(uint64) (viewchange.ChangeSet, error) {
return gov.changeset, nil
}

type fakeQueue struct {
Expand Down
14 changes: 13 additions & 1 deletion consensus/viewchange/mod.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package viewchange

import (
"github.com/golang/protobuf/proto"
"go.dedis.ch/fabric/consensus"
"go.dedis.ch/fabric/crypto"
"go.dedis.ch/fabric/encoding"
"go.dedis.ch/fabric/mino"
)

Expand Down Expand Up @@ -35,22 +37,32 @@ type ChangeSet struct {
// EvolvableAuthority is an extension of the collective authority to provide
// primitives to append new players to it.
type EvolvableAuthority interface {
encoding.Packable
crypto.CollectiveAuthority

// Apply must apply the change set to the collective authority. It should
// first remove, then add the new players.
Apply(ChangeSet) EvolvableAuthority
}

// AuthorityFactory is an interface to instantiate evolvable authorities.
type AuthorityFactory interface {
New(crypto.CollectiveAuthority) EvolvableAuthority

FromProto(proto.Message) (EvolvableAuthority, error)
}

// Governance is an interface to get information about the collective authority
// of a proposal.
type Governance interface {
GetAuthorityFactory() AuthorityFactory

// GetAuthority must return the authority that governs the proposal at the
// given index. It will be used to sign the forward link to the next
// proposal.
GetAuthority(index uint64) (EvolvableAuthority, error)

// GetChangeSet must return the changes to the authority that will be
// applied for the proposal following the given index.
GetChangeSet(index uint64) ChangeSet
GetChangeSet(index uint64) (ChangeSet, error)
}
5 changes: 5 additions & 0 deletions encoding/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ type ProtoMarshaler interface {
UnmarshalDynamicAny(any *any.Any) (proto.Message, error)
}

// Fingerprinter is an interface to perform fingerprinting on object.
type Fingerprinter interface {
Fingerprint(io.Writer, ProtoMarshaler) error
}

// ProtoEncoder is a default implementation of protobug encoding/decoding.
type ProtoEncoder struct {
marshaler *jsonpb.Marshaler
Expand Down
44 changes: 44 additions & 0 deletions internal/testing/fake/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,28 @@ type Call struct {

// Get returns the nth call ith parameter.
func (c *Call) Get(n, i int) interface{} {
if c == nil {
return nil
}

return c.calls[n][i]
}

// Len returns the number of calls.
func (c *Call) Len() int {
if c == nil {
return 0
}

return len(c.calls)
}

// Add adds a call to the list.
func (c *Call) Add(args ...interface{}) {
if c == nil {
return
}

c.calls = append(c.calls, args)
}

Expand Down Expand Up @@ -123,6 +135,7 @@ func (i *PublicKeyIterator) GetNext() crypto.PublicKey {
// CollectiveAuthority is a fake implementation of the cosi.CollectiveAuthority
// interface.
type CollectiveAuthority struct {
encoding.Packable
crypto.CollectiveAuthority
addrs []mino.Address
signers []crypto.AggregateSigner
Expand Down Expand Up @@ -379,6 +392,11 @@ func (pk PublicKey) Pack(encoding.ProtoMarshaler) (proto.Message, error) {
return &empty.Empty{}, pk.err
}

// String implements fmt.Stringer.
func (pk PublicKey) String() string {
return "fake.PublicKey"
}

// Signer is a fake implementation of the crypto.AggregateSigner interface.
type Signer struct {
crypto.AggregateSigner
Expand Down Expand Up @@ -489,6 +507,27 @@ func (f VerifierFactory) FromAuthority(ca crypto.CollectiveAuthority) (crypto.Ve
return f.verifier, f.err
}

// Counter is a helper to delay errors or actions. It can be nil without panics.
type Counter struct {
Value int
}

// Done returns true when the counter reached zero.
func (c *Counter) Done() bool {
if c == nil {
return true
}
return c.Value <= 0
}

// Decrease decrements the counter.
func (c *Counter) Decrease() {
if c == nil {
return
}
c.Value--
}

// BadPackEncoder is a fake implementation of encoding.ProtoMarshaler.
type BadPackEncoder struct {
encoding.ProtoEncoder
Expand All @@ -502,10 +541,15 @@ func (e BadPackEncoder) Pack(encoding.Packable) (proto.Message, error) {
// BadPackAnyEncoder is a fake implementation of encoding.ProtoMarshaler.
type BadPackAnyEncoder struct {
encoding.ProtoEncoder
Counter *Counter
}

// PackAny implements encoding.ProtoMarshaler.
func (e BadPackAnyEncoder) PackAny(encoding.Packable) (*any.Any, error) {
defer e.Counter.Decrease()
if !e.Counter.Done() {
return &any.Any{}, nil
}
return nil, xerrors.New("fake error")
}

Expand Down
2 changes: 1 addition & 1 deletion ledger/arc/common/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewAccessControlFactory() *AccessControlFactory {
factories: make(map[reflect.Type]arc.AccessControlFactory),
}

factory.Register((*darc.AccessControlProto)(nil), darc.Factory{})
factory.Register((*darc.AccessProto)(nil), darc.Factory{})

return factory
}
Expand Down
101 changes: 0 additions & 101 deletions ledger/arc/darc/contract/mod.go

This file was deleted.

Loading

0 comments on commit 92e3aa0

Please sign in to comment.