Skip to content

Commit

Permalink
Address nkcr's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilthoniel committed May 1, 2020
1 parent 113521c commit e52db0b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
22 changes: 13 additions & 9 deletions consensus/cosipbft/forward_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,35 @@ func (fl forwardLink) Verify(v crypto.Verifier) error {

// Pack returns the protobuf message of the forward link.
func (fl forwardLink) Pack(enc encoding.ProtoMarshaler) (proto.Message, error) {
pb := &ForwardLinkProto{
From: fl.from,
To: fl.to,
}

var err error
pb.ChangeSet, err = fl.packChangeSet(enc)
changeset, err := fl.packChangeSet(enc)
if err != nil {
return nil, xerrors.Errorf("couldn't pack changeset: %v", err)
}

var prepare *any.Any
if fl.prepare != nil {
pb.Prepare, err = enc.PackAny(fl.prepare)
prepare, err = enc.PackAny(fl.prepare)
if err != nil {
return nil, xerrors.Errorf("couldn't pack prepare signature: %v", err)
}
}

var commit *any.Any
if fl.commit != nil {
pb.Commit, err = enc.PackAny(fl.commit)
commit, err = enc.PackAny(fl.commit)
if err != nil {
return nil, xerrors.Errorf("couldn't pack commit signature: %v", err)
}
}

pb := &ForwardLinkProto{
From: fl.from,
To: fl.to,
Prepare: prepare,
Commit: commit,
ChangeSet: changeset,
}

return pb, nil
}

Expand Down
4 changes: 2 additions & 2 deletions docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ definitions of modular pieces that build a blockchain.
algorithm that can be used to verify the integrity of some data. One example
is the inventory page integrity to prove which instances are stored.

- **governance** - Governance is a black box that provides to act on the
participants of a consensus.
- **governance** - Governance is a black box that gives the ability to act on
the participants of a consensus.

- **instance** - An instance is the smallest unit of storage in a ledger. It is
identified by a unique key and stores a generic piece of data.
Expand Down
30 changes: 18 additions & 12 deletions ledger/byzcoin/roster.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,27 @@ func (r roster) PublicKeyIterator() crypto.PublicKeyIterator {
// Pack implements encoding.Packable. It returns the protobuf message for the
// roster.
func (r roster) Pack(enc encoding.ProtoMarshaler) (proto.Message, error) {
pb := &Roster{
Addresses: make([][]byte, r.Len()),
PublicKeys: make([]*any.Any, r.Len()),
}
addrs := make([][]byte, r.Len())
pubkeys := make([]*any.Any, r.Len())

var err error
for i, addr := range r.addrs {
pb.Addresses[i], err = addr.MarshalText()
addrs[i], err = addr.MarshalText()
if err != nil {
return nil, xerrors.Errorf("couldn't marshal address: %v", err)
}

pb.PublicKeys[i], err = enc.PackAny(r.pubkeys[i])
pubkeys[i], err = enc.PackAny(r.pubkeys[i])
if err != nil {
return nil, xerrors.Errorf("couldn't pack public key: %v", err)
}
}

pb := &Roster{
Addresses: addrs,
PublicKeys: pubkeys,
}

return pb, nil
}

Expand All @@ -159,16 +162,19 @@ func newRosterFactory(af mino.AddressFactory, pf crypto.PublicKeyFactory) roster
}

func (f rosterFactory) New(authority crypto.CollectiveAuthority) roster {
roster := roster{
addrs: make([]mino.Address, authority.Len()),
pubkeys: make([]crypto.PublicKey, authority.Len()),
}
addrs := make([]mino.Address, authority.Len())
pubkeys := make([]crypto.PublicKey, authority.Len())

addrIter := authority.AddressIterator()
pubkeyIter := authority.PublicKeyIterator()
for i := 0; addrIter.HasNext() && pubkeyIter.HasNext(); i++ {
roster.addrs[i] = addrIter.GetNext()
roster.pubkeys[i] = pubkeyIter.GetNext()
addrs[i] = addrIter.GetNext()
pubkeys[i] = pubkeyIter.GetNext()
}

roster := roster{
addrs: addrs,
pubkeys: pubkeys,
}

return roster
Expand Down

0 comments on commit e52db0b

Please sign in to comment.