Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilthoniel committed May 13, 2020
1 parent f067472 commit fcddbb2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
4 changes: 3 additions & 1 deletion blockchain/skipchain/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ func (ops *operations) catchUp(target SkipBlock, addr mino.Address) error {
return nil
}

ops.logger.Info().Msg("one or more blocks are missing: starting catch up")
ops.logger.Info().
Str("addr", ops.addr.String()).
Msg("one or more blocks are missing: starting catch up")

from := uint64(0)
if ops.db.Contains(0) {
Expand Down
1 change: 1 addition & 0 deletions blockchain/skipchain/ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestOperations_CatchUp(t *testing.T) {
require.NoError(t, err)

ops := &operations{
addr: fake.NewAddress(0),
blockFactory: blockFactory{
encoder: encoding.NewProtoEncoder(),
hashFactory: crypto.NewSha256Factory(),
Expand Down
20 changes: 11 additions & 9 deletions consensus/cosipbft/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,18 @@ func (a pbftActor) Propose(p consensus.Proposal) error {
defer cancel()

resps, errs := a.rpc.Call(ctx, propagateReq, authority)
select {
case <-a.closing:
// Abort the RPC call.
cancel()
case <-resps:
case err := <-errs:
return xerrors.Errorf("couldn't propagate the link: %v", err)
for {
select {
case <-a.closing:
// Abort the RPC call.
cancel()
return nil
case <-resps:
return nil
case err := <-errs:
fabric.Logger.Warn().Err(err).Msg("couldn't propagate the link")
}
}

return nil
}

func (a pbftActor) newPrepareRequest(prop consensus.Proposal,
Expand Down
17 changes: 7 additions & 10 deletions consensus/cosipbft/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func TestConsensus_Store(t *testing.T) {
}

func TestActor_Propose(t *testing.T) {
rpc := &fakeRPC{close: true}
rpc := &fakeRPC{}
cosiActor := &fakeCosiActor{}
actor := &pbftActor{
Consensus: &Consensus{
Expand Down Expand Up @@ -245,7 +245,6 @@ func TestActor_Propose(t *testing.T) {
require.Equal(t, []byte{0xaa}, propagate.GetTo())
checkSignatureValue(t, propagate.GetCommit())

rpc.close = false
require.NoError(t, actor.Close())
err = actor.Propose(fakeProposal{})
require.NoError(t, err)
Expand Down Expand Up @@ -302,11 +301,11 @@ func TestActor_Failures_Propose(t *testing.T) {
err = actor.Propose(fakeProposal{})
require.EqualError(t, err, "couldn't pack signature: fake error")

actor.encoder = encoding.NewProtoEncoder()
actor.cosiActor = &fakeCosiActor{}
actor.rpc = &fakeRPC{err: xerrors.New("oops")}
err = actor.Propose(fakeProposal{})
require.EqualError(t, err, "couldn't propagate the link: oops")
// actor.encoder = encoding.NewProtoEncoder()
// actor.cosiActor = &fakeCosiActor{}
// actor.rpc = &fakeRPC{err: xerrors.New("oops")}
// err = actor.Propose(fakeProposal{})
// require.EqualError(t, err, "couldn't propagate the link: oops")
}

func TestActor_Close(t *testing.T) {
Expand Down Expand Up @@ -697,18 +696,16 @@ type fakeRPC struct {

calls []map[string]interface{}
err error
close bool
}

func (rpc *fakeRPC) Call(ctx context.Context, pb proto.Message,
memship mino.Players) (<-chan proto.Message, <-chan error) {

msgs := make(chan proto.Message)
close(msgs)
errs := make(chan error, 1)
if rpc.err != nil {
errs <- rpc.err
} else if rpc.close {
close(msgs)
}
rpc.calls = append(rpc.calls, map[string]interface{}{
"message": pb,
Expand Down
2 changes: 1 addition & 1 deletion ledger/byzcoin/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func sendTx(t *testing.T, ledger ledger.Ledger, actor ledger.Actor, tx transacti
if bytes.Equal(tx.GetID(), res.GetTransactionID()) {
return
}
case <-time.After(1 * time.Second):
case <-time.After(5 * time.Second):
t.Fatal("timeout when waiting for the transaction")
}
}
Expand Down

0 comments on commit fcddbb2

Please sign in to comment.