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 13, 2020
1 parent 2dfb970 commit c58010d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions blockchain/skipchain/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"golang.org/x/xerrors"
)

// operations implements helper functions that can be used by the handlers for
// common operations.
type operations struct {
logger zerolog.Logger
encoder encoding.ProtoMarshaler
Expand Down
7 changes: 4 additions & 3 deletions consensus/cosipbft/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ func (c *Consensus) Store(in consensus.Chain) error {
return xerrors.Errorf("couldn't read latest chain: %v", err)
}

store := false
for _, link := range chain.links {
if last == nil || bytes.Equal(last.To, link.from[:]) {
store = store || last == nil || bytes.Equal(last.To, link.from[:])

if store {
linkpb, err := c.encoder.Pack(link)
if err != nil {
return xerrors.Errorf("couldn't pack link: %v", err)
Expand All @@ -131,8 +134,6 @@ func (c *Consensus) Store(in consensus.Chain) error {
if err != nil {
return xerrors.Errorf("couldn't store link: %v", err)
}

last = nil
}
}

Expand Down
5 changes: 2 additions & 3 deletions ledger/byzcoin/roster/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (t clientTask) GetChangeSet() viewchange.ChangeSet {
if removals[i] == removals[i+1] {
removals = append(removals[:i], removals[i+1:]...)
} else {
// Only moves to the next when all occurances of the same index are
// Only moves to the next when all occurences of the same index are
// removed.
i++
}
Expand Down Expand Up @@ -296,8 +296,7 @@ func (f TaskManager) FromProto(in proto.Message) (basic.ServerTask, error) {

player, err := f.unpackPlayer(pb.GetAddr(), pb.GetPublicKey())
if err != nil {
// The error is not wrap to avoid redundancy with the private function.
return nil, err
return nil, xerrors.Errorf("couldn't unpack player: %v", err)
}

task := serverTask{
Expand Down
3 changes: 2 additions & 1 deletion ledger/byzcoin/roster/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ func TestTaskManager_FromProto(t *testing.T) {
factory = NewRosterFactory(fake.AddressFactory{}, fake.NewBadPublicKeyFactory())
manager = NewTaskManager(factory, nil)
_, err = manager.FromProto(&Task{Addr: []byte{}, PublicKey: &any.Any{}})
require.EqualError(t, err, "couldn't decode public key: fake error")
require.EqualError(t, err,
"couldn't unpack player: couldn't decode public key: fake error")
}

// -----------------------------------------------------------------------------
Expand Down

0 comments on commit c58010d

Please sign in to comment.