From 0a0c5a970377d3706657af8e630123662ad52722 Mon Sep 17 00:00:00 2001 From: Yoav Tock Date: Tue, 30 May 2023 11:59:30 +0300 Subject: [PATCH] BFT Block Puller: verify attestation Signed-off-by: Yoav Tock Change-Id: Ia34ff4536453581895c4f13b2d73f0e7066ce125 --- gossip/api/crypto.go | 5 + gossip/comm/comm_test.go | 6 + gossip/gossip/channel/channel_test.go | 4 + gossip/gossip/gossip_test.go | 6 + gossip/gossip/orgs_test.go | 6 + gossip/identity/identity_test.go | 6 + gossip/service/gossip_service_test.go | 6 + gossip/state/state_test.go | 6 + internal/peer/gossip/mcs.go | 23 +++ internal/peer/gossip/mcs_test.go | 154 +++++++++++++----- .../pkg/peer/blocksprovider/blocksprovider.go | 5 + .../blocksprovider/fake/block_verifier.go | 83 +++++++++- .../blocksprovider/fake/deliver_streamer.go | 7 +- .../pkg/peer/blocksprovider/fake/dialer.go | 7 +- .../fake/gossip_service_adapter.go | 10 +- .../peer/blocksprovider/fake/ledger_info.go | 7 +- .../fake/orderer_connection_source.go | 7 +- 17 files changed, 287 insertions(+), 61 deletions(-) diff --git a/gossip/api/crypto.go b/gossip/api/crypto.go index e4817ff5a89..2c58c1a0291 100644 --- a/gossip/api/crypto.go +++ b/gossip/api/crypto.go @@ -37,6 +37,11 @@ type MessageCryptoService interface { // else returns error VerifyBlock(channelID common.ChannelID, seqNum uint64, block *cb.Block) error + // VerifyBlockAttestation does the same as VerifyBlock, except it assumes block.Data = nil. It therefore does not + // compute the block.Data.Hash() and compare it to the block.Header.DataHash. This is used when the orderer + // delivers a block with header & metadata only, as an attestation of block existence. + VerifyBlockAttestation(channelID string, block *cb.Block) error + // Sign signs msg with this peer's signing key and outputs // the signature if no error occurred. Sign(msg []byte) ([]byte, error) diff --git a/gossip/comm/comm_test.go b/gossip/comm/comm_test.go index 4d18706c21b..75043b3c3c5 100644 --- a/gossip/comm/comm_test.go +++ b/gossip/comm/comm_test.go @@ -97,6 +97,12 @@ func (*naiveSecProvider) VerifyBlock(channelID common.ChannelID, seqNum uint64, return nil } +// VerifyBlockAttestation returns nil if the block attestation is properly signed, +// else returns error +func (*naiveSecProvider) VerifyBlockAttestation(channelID string, signedBlock *cb.Block) error { + return nil +} + // Sign signs msg with this peer's signing key and outputs // the signature if no error occurred. func (*naiveSecProvider) Sign(msg []byte) ([]byte, error) { diff --git a/gossip/gossip/channel/channel_test.go b/gossip/gossip/channel/channel_test.go index a7df0416e93..30d54f3f8b5 100644 --- a/gossip/gossip/channel/channel_test.go +++ b/gossip/gossip/channel/channel_test.go @@ -146,6 +146,10 @@ func (cs *cryptoService) VerifyBlock(channelID common.ChannelID, seqNum uint64, return args.Get(0).(error) } +func (*cryptoService) VerifyBlockAttestation(channelID string, signedBlock *cb.Block) error { + panic("Should not be called in this test") +} + func (cs *cryptoService) Sign(msg []byte) ([]byte, error) { panic("Should not be called in this test") } diff --git a/gossip/gossip/gossip_test.go b/gossip/gossip/gossip_test.go index 81372650cc4..80ca8b30278 100644 --- a/gossip/gossip/gossip_test.go +++ b/gossip/gossip/gossip_test.go @@ -177,6 +177,12 @@ func (*naiveCryptoService) VerifyBlock(channelID common.ChannelID, seqNum uint64 return nil } +// VerifyBlockAttestation returns nil if the block attestation is properly signed, +// else returns error +func (*naiveCryptoService) VerifyBlockAttestation(channelID string, signedBlock *cb.Block) error { + return nil +} + // Sign signs msg with this peer's signing key and outputs // the signature if no error occurred. func (*naiveCryptoService) Sign(msg []byte) ([]byte, error) { diff --git a/gossip/gossip/orgs_test.go b/gossip/gossip/orgs_test.go index 6258591baef..5e8e882984e 100644 --- a/gossip/gossip/orgs_test.go +++ b/gossip/gossip/orgs_test.go @@ -81,6 +81,12 @@ func (*configurableCryptoService) VerifyBlock(channelID common.ChannelID, seqNum return nil } +// VerifyBlockAttestation returns nil if the block attestation is properly signed, +// else returns error +func (*configurableCryptoService) VerifyBlockAttestation(channelID string, signedBlock *cb.Block) error { + return nil +} + // Sign signs msg with this peer's signing key and outputs // the signature if no error occurred. func (*configurableCryptoService) Sign(msg []byte) ([]byte, error) { diff --git a/gossip/identity/identity_test.go b/gossip/identity/identity_test.go index 28da61c0ac5..5dd2c20f3b8 100644 --- a/gossip/identity/identity_test.go +++ b/gossip/identity/identity_test.go @@ -82,6 +82,12 @@ func (*naiveCryptoService) VerifyBlock(channelID common.ChannelID, seqNum uint64 return nil } +// VerifyBlockAttestation returns nil if the block attestation is properly signed, +// else returns error +func (*naiveCryptoService) VerifyBlockAttestation(channelID string, signedBlock *cb.Block) error { + return nil +} + // VerifyByChannel verifies a peer's signature on a message in the context // of a specific channel func (*naiveCryptoService) VerifyByChannel(_ common.ChannelID, _ api.PeerIdentityType, _, _ []byte) error { diff --git a/gossip/service/gossip_service_test.go b/gossip/service/gossip_service_test.go index 8842a6eaaa5..e2813e3e295 100644 --- a/gossip/service/gossip_service_test.go +++ b/gossip/service/gossip_service_test.go @@ -843,6 +843,12 @@ func (*naiveCryptoService) VerifyBlock(chainID gossipcommon.ChannelID, seqNum ui return nil } +// VerifyBlockAttestation returns nil if the block attestation is properly signed, +// else returns error +func (*naiveCryptoService) VerifyBlockAttestation(channelID string, signedBlock *common.Block) error { + return nil +} + // Sign signs msg with this peer's signing key and outputs // the signature if no error occurred. func (*naiveCryptoService) Sign(msg []byte) ([]byte, error) { diff --git a/gossip/state/state_test.go b/gossip/state/state_test.go index 65e31c80dab..ab6750b4835 100644 --- a/gossip/state/state_test.go +++ b/gossip/state/state_test.go @@ -121,6 +121,12 @@ func (*cryptoServiceMock) VerifyBlock(channelID common.ChannelID, seqNum uint64, return nil } +// VerifyBlockAttestation returns nil if the block attestation is properly signed, +// else returns error +func (*cryptoServiceMock) VerifyBlockAttestation(channelID string, signedBlock *pcomm.Block) error { + return nil +} + // Sign signs msg with this peer's signing key and outputs // the signature if no error occurred. func (*cryptoServiceMock) Sign(msg []byte) ([]byte, error) { diff --git a/internal/peer/gossip/mcs.go b/internal/peer/gossip/mcs.go index a91e6dbd489..6e1913d8999 100644 --- a/internal/peer/gossip/mcs.go +++ b/internal/peer/gossip/mcs.go @@ -156,6 +156,10 @@ func (s *MSPMessageCryptoService) VerifyBlock(chainID common.ChannelID, seqNum u return fmt.Errorf("Header.DataHash is different from Hash(block.Data) for block with id [%d] on channel [%s]", block.Header.Number, chainID) } + return s.verifyHeaderAndMetadata(channelID, block) +} + +func (s *MSPMessageCryptoService) verifyHeaderAndMetadata(channelID string, block *pcommon.Block) error { // Get the policy manager for channelID cpm := s.channelPolicyManagerGetter.Manager(channelID) if cpm == nil { @@ -184,6 +188,25 @@ func (s *MSPMessageCryptoService) VerifyBlock(chainID common.ChannelID, seqNum u return verifier(block.Header, block.Metadata) } +// VerifyBlockAttestation returns nil when the header matches the metadata signature. It assumed the block.Data is nil +// and therefore does not verify that Header.DataHash is equal to the hash of block.Data. This is used when the orderer +// delivers a block with header & metadata only, as an attestation of block existence. +func (s *MSPMessageCryptoService) VerifyBlockAttestation(chainID string, block *pcommon.Block) error { + if block == nil { + return fmt.Errorf("Invalid Block on channel [%s]. Block is nil.", chainID) + } + if block.Header == nil { + return fmt.Errorf("Invalid Block on channel [%s]. Header must be different from nil.", chainID) + } + + // - Unmarshal medatada + if block.Metadata == nil || len(block.Metadata.Metadata) == 0 { + return fmt.Errorf("Block with id [%d] on channel [%s] does not have metadata. Block not valid.", block.Header.Number, chainID) + } + + return s.verifyHeaderAndMetadata(chainID, block) +} + // Sign signs msg with this peer's signing key and outputs // the signature if no error occurred. func (s *MSPMessageCryptoService) Sign(msg []byte) ([]byte, error) { diff --git a/internal/peer/gossip/mcs_test.go b/internal/peer/gossip/mcs_test.go index 74643d58353..cb2e33b970a 100644 --- a/internal/peer/gossip/mcs_test.go +++ b/internal/peer/gossip/mcs_test.go @@ -28,6 +28,7 @@ import ( "github.com/hyperledger/fabric/msp" "github.com/hyperledger/fabric/msp/mgmt" "github.com/hyperledger/fabric/protoutil" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -289,28 +290,68 @@ func TestVerifyBlock(t *testing.T) { blockRaw2, msg2 := mockBlock(t, "D", 42, aliceSigner, nil) policyManagerGetter.Managers["D"].(*mocks.ChannelPolicyManager).Policy.(*mocks.Policy).Deserializer.(*mocks.IdentityDeserializer).Msg = msg2 - // - Verify block - require.NoError(t, msgCryptoService.VerifyBlock([]byte("C"), 42, blockRaw)) - // Wrong sequence number claimed - err = msgCryptoService.VerifyBlock([]byte("C"), 43, blockRaw) - require.Error(t, err) - require.Contains(t, err.Error(), "but actual seqNum inside block is") - delete(policyManagerGetter.Managers, "D") - nilPolMgrErr := msgCryptoService.VerifyBlock([]byte("D"), 42, blockRaw2) - require.Contains(t, nilPolMgrErr.Error(), "Could not acquire policy manager") - require.Error(t, nilPolMgrErr) - require.Error(t, msgCryptoService.VerifyBlock([]byte("A"), 42, blockRaw)) - require.Error(t, msgCryptoService.VerifyBlock([]byte("B"), 42, blockRaw)) - - // - Prepare testing invalid block (wrong data has), Alice signs it. - blockRaw, msg = mockBlock(t, "C", 42, aliceSigner, []byte{0}) - policyManagerGetter.Managers["C"].(*mocks.ChannelPolicyManager).Policy.(*mocks.Policy).Deserializer.(*mocks.IdentityDeserializer).Msg = msg - - // - Verify block - require.Error(t, msgCryptoService.VerifyBlock([]byte("C"), 42, blockRaw)) + t.Run("verify block", func(t *testing.T) { + require.NoError(t, msgCryptoService.VerifyBlock([]byte("C"), 42, blockRaw)) + // Wrong sequence number claimed + err = msgCryptoService.VerifyBlock([]byte("C"), 43, blockRaw) + require.Error(t, err) + require.Contains(t, err.Error(), "but actual seqNum inside block is") + delete(policyManagerGetter.Managers, "D") + nilPolMgrErr := msgCryptoService.VerifyBlock([]byte("D"), 42, blockRaw2) + require.Contains(t, nilPolMgrErr.Error(), "Could not acquire policy manager") + require.Error(t, nilPolMgrErr) + require.Error(t, msgCryptoService.VerifyBlock([]byte("A"), 42, blockRaw)) + require.Error(t, msgCryptoService.VerifyBlock([]byte("B"), 42, blockRaw)) + + // - Prepare testing invalid block (wrong data has), Alice signs it. + blockRawInvalid, msgInvalid := mockBlock(t, "C", 42, aliceSigner, []byte{0}) + policyManagerGetter.Managers["C"].(*mocks.ChannelPolicyManager).Policy.(*mocks.Policy).Deserializer.(*mocks.IdentityDeserializer).Msg = msgInvalid + defer func() { + policyManagerGetter.Managers["C"].(*mocks.ChannelPolicyManager).Policy.(*mocks.Policy).Deserializer.(*mocks.IdentityDeserializer).Msg = msg + }() + + // - Verify block + require.Error(t, msgCryptoService.VerifyBlock([]byte("C"), 42, blockRawInvalid)) + + // Check invalid args + require.Error(t, msgCryptoService.VerifyBlock([]byte("C"), 42, &common.Block{})) + }) - // Check invalid args - require.Error(t, msgCryptoService.VerifyBlock([]byte("C"), 42, &common.Block{})) + t.Run("verify block attestation", func(t *testing.T) { + // An attestation is a signed block with block.Data = nil + attestation := blockRaw + attestation.Data = nil + attestation2 := blockRaw2 + attestation2.Data = nil + + assert.NoError(t, msgCryptoService.VerifyBlockAttestation("C", attestation)) + delete(policyManagerGetter.Managers, "D") + nilPolMgrErr := msgCryptoService.VerifyBlockAttestation("D", attestation2) + assert.Contains(t, nilPolMgrErr.Error(), "Could not acquire policy manager") + assert.Error(t, nilPolMgrErr) + assert.Error(t, msgCryptoService.VerifyBlockAttestation("A", attestation)) + assert.Error(t, msgCryptoService.VerifyBlockAttestation("B", attestation)) + + // - Prepare testing invalid attestation (wrong data has), Alice signs it. + // - Prepare testing invalid attestation (wrong data has), Alice signs it. + _, msgInvalid := mockBlock(t, "C", 42, aliceSigner, []byte{0}) + policyManagerGetter.Managers["C"].(*mocks.ChannelPolicyManager).Policy.(*mocks.Policy).Deserializer.(*mocks.IdentityDeserializer).Msg = msgInvalid + defer func() { + policyManagerGetter.Managers["C"].(*mocks.ChannelPolicyManager).Policy.(*mocks.Policy).Deserializer.(*mocks.IdentityDeserializer).Msg = msg + }() + + // - Verify attestation + assert.Error(t, msgCryptoService.VerifyBlockAttestation("C", attestation)) + + // Check invalid args + attestation.Header.DataHash = []byte{0, 1, 2, 3, 4} + assert.Error(t, msgCryptoService.VerifyBlockAttestation("C", attestation)) + attestation.Metadata = nil + assert.Error(t, msgCryptoService.VerifyBlockAttestation("C", attestation)) + attestation.Header = nil + assert.Error(t, msgCryptoService.VerifyBlockAttestation("C", attestation)) + assert.Error(t, msgCryptoService.VerifyBlockAttestation("C", nil)) + }) } func TestVerifyBlockBFT(t *testing.T) { @@ -368,28 +409,57 @@ func TestVerifyBlockBFT(t *testing.T) { blockRaw2, msg2 := mockBlockBFT(t, "D", 42, aliceSigner, nil) policyManagerGetter.Managers["D"].(*mocks.ChannelPolicyManager).Policy.(*mocks.Policy).Deserializer.(*mocks.IdentityDeserializer).Msg = msg2 - // - Verify block - require.NoError(t, msgCryptoService.VerifyBlock([]byte("C"), 42, blockRaw)) - // Wrong sequence number claimed - err = msgCryptoService.VerifyBlock([]byte("C"), 43, blockRaw) - require.Error(t, err) - require.Contains(t, err.Error(), "but actual seqNum inside block is") - delete(policyManagerGetter.Managers, "D") - nilPolMgrErr := msgCryptoService.VerifyBlock([]byte("D"), 42, blockRaw2) - require.Contains(t, nilPolMgrErr.Error(), "Could not acquire policy manager") - require.Error(t, nilPolMgrErr) - require.Error(t, msgCryptoService.VerifyBlock([]byte("A"), 42, blockRaw)) - require.Error(t, msgCryptoService.VerifyBlock([]byte("B"), 42, blockRaw)) - - // - Prepare testing invalid block (wrong data has), Alice signs it. - blockRaw, msg = mockBlockBFT(t, "C", 42, aliceSigner, []byte{0}) - policyManagerGetter.Managers["C"].(*mocks.ChannelPolicyManager).Policy.(*mocks.Policy).Deserializer.(*mocks.IdentityDeserializer).Msg = msg - - // - Verify block - require.Error(t, msgCryptoService.VerifyBlock([]byte("C"), 42, blockRaw)) + t.Run("verify block", func(t *testing.T) { + // - Verify block + require.NoError(t, msgCryptoService.VerifyBlock([]byte("C"), 42, blockRaw)) + // Wrong sequence number claimed + err = msgCryptoService.VerifyBlock([]byte("C"), 43, blockRaw) + require.Error(t, err) + require.Contains(t, err.Error(), "but actual seqNum inside block is") + delete(policyManagerGetter.Managers, "D") + nilPolMgrErr := msgCryptoService.VerifyBlock([]byte("D"), 42, blockRaw2) + require.Contains(t, nilPolMgrErr.Error(), "Could not acquire policy manager") + require.Error(t, nilPolMgrErr) + require.Error(t, msgCryptoService.VerifyBlock([]byte("A"), 42, blockRaw)) + require.Error(t, msgCryptoService.VerifyBlock([]byte("B"), 42, blockRaw)) + + // - Prepare testing invalid block (wrong data has), Alice signs it. + blockRawInvalid, msgInvalid := mockBlockBFT(t, "C", 42, aliceSigner, []byte{0}) + policyManagerGetter.Managers["C"].(*mocks.ChannelPolicyManager).Policy.(*mocks.Policy).Deserializer.(*mocks.IdentityDeserializer).Msg = msgInvalid + defer func() { + policyManagerGetter.Managers["C"].(*mocks.ChannelPolicyManager).Policy.(*mocks.Policy).Deserializer.(*mocks.IdentityDeserializer).Msg = msg + }() + // - Verify block + require.Error(t, msgCryptoService.VerifyBlock([]byte("C"), 42, blockRawInvalid)) + + // Check invalid args + require.Error(t, msgCryptoService.VerifyBlock([]byte("C"), 42, &common.Block{})) + }) - // Check invalid args - require.Error(t, msgCryptoService.VerifyBlock([]byte("C"), 42, &common.Block{})) + t.Run("verify block attestation", func(t *testing.T) { + // An attestation is a signed block with block.Data = nil + attestation := blockRaw + attestation.Data = nil + attestation2 := blockRaw2 + attestation2.Data = nil + + // - Verify block + require.NoError(t, msgCryptoService.VerifyBlockAttestation("C", attestation)) + nilPolMgrErr := msgCryptoService.VerifyBlockAttestation("D", attestation2) + require.Contains(t, nilPolMgrErr.Error(), "Could not acquire policy manager") + require.Error(t, nilPolMgrErr) + require.Error(t, msgCryptoService.VerifyBlockAttestation("A", attestation)) + require.Error(t, msgCryptoService.VerifyBlockAttestation("B", attestation)) + + // - Prepare testing invalid block (has wrong data), Alice signs it. + _, msgInvalid := mockBlockBFT(t, "C", 42, aliceSigner, []byte{0}) + policyManagerGetter.Managers["C"].(*mocks.ChannelPolicyManager).Policy.(*mocks.Policy).Deserializer.(*mocks.IdentityDeserializer).Msg = msgInvalid + defer func() { + policyManagerGetter.Managers["C"].(*mocks.ChannelPolicyManager).Policy.(*mocks.Policy).Deserializer.(*mocks.IdentityDeserializer).Msg = msg + }() + // - Verify block + require.Error(t, msgCryptoService.VerifyBlockAttestation("C", attestation)) + }) } func mockBlock(t *testing.T, channel string, seqNum uint64, localSigner *mocks.SignerSerializer, dataHash []byte) (*common.Block, []byte) { diff --git a/internal/pkg/peer/blocksprovider/blocksprovider.go b/internal/pkg/peer/blocksprovider/blocksprovider.go index bacc5dbc6f5..45f602042d8 100644 --- a/internal/pkg/peer/blocksprovider/blocksprovider.go +++ b/internal/pkg/peer/blocksprovider/blocksprovider.go @@ -66,6 +66,11 @@ type GossipServiceAdapter interface { //go:generate counterfeiter -o fake/block_verifier.go --fake-name BlockVerifier . BlockVerifier type BlockVerifier interface { VerifyBlock(channelID gossipcommon.ChannelID, blockNum uint64, block *common.Block) error + + // VerifyBlockAttestation does the same as VerifyBlock, except it assumes block.Data = nil. It therefore does not + // compute the block.Data.Hash() and compare it to the block.Header.DataHash. This is used when the orderer + // delivers a block with header & metadata only, as an attestation of block existence. + VerifyBlockAttestation(channelID string, block *common.Block) error } //go:generate counterfeiter -o fake/orderer_connection_source.go --fake-name OrdererConnectionSource . OrdererConnectionSource diff --git a/internal/pkg/peer/blocksprovider/fake/block_verifier.go b/internal/pkg/peer/blocksprovider/fake/block_verifier.go index c1ae3449f57..7c3b2b385a2 100644 --- a/internal/pkg/peer/blocksprovider/fake/block_verifier.go +++ b/internal/pkg/peer/blocksprovider/fake/block_verifier.go @@ -23,6 +23,18 @@ type BlockVerifier struct { verifyBlockReturnsOnCall map[int]struct { result1 error } + VerifyBlockAttestationStub func(string, *commona.Block) error + verifyBlockAttestationMutex sync.RWMutex + verifyBlockAttestationArgsForCall []struct { + arg1 string + arg2 *commona.Block + } + verifyBlockAttestationReturns struct { + result1 error + } + verifyBlockAttestationReturnsOnCall map[int]struct { + result1 error + } invocations map[string][][]interface{} invocationsMutex sync.RWMutex } @@ -35,15 +47,16 @@ func (fake *BlockVerifier) VerifyBlock(arg1 common.ChannelID, arg2 uint64, arg3 arg2 uint64 arg3 *commona.Block }{arg1, arg2, arg3}) + stub := fake.VerifyBlockStub + fakeReturns := fake.verifyBlockReturns fake.recordInvocation("VerifyBlock", []interface{}{arg1, arg2, arg3}) fake.verifyBlockMutex.Unlock() - if fake.VerifyBlockStub != nil { - return fake.VerifyBlockStub(arg1, arg2, arg3) + if stub != nil { + return stub(arg1, arg2, arg3) } if specificReturn { return ret.result1 } - fakeReturns := fake.verifyBlockReturns return fakeReturns.result1 } @@ -89,11 +102,75 @@ func (fake *BlockVerifier) VerifyBlockReturnsOnCall(i int, result1 error) { }{result1} } +func (fake *BlockVerifier) VerifyBlockAttestation(arg1 string, arg2 *commona.Block) error { + fake.verifyBlockAttestationMutex.Lock() + ret, specificReturn := fake.verifyBlockAttestationReturnsOnCall[len(fake.verifyBlockAttestationArgsForCall)] + fake.verifyBlockAttestationArgsForCall = append(fake.verifyBlockAttestationArgsForCall, struct { + arg1 string + arg2 *commona.Block + }{arg1, arg2}) + stub := fake.VerifyBlockAttestationStub + fakeReturns := fake.verifyBlockAttestationReturns + fake.recordInvocation("VerifyBlockAttestation", []interface{}{arg1, arg2}) + fake.verifyBlockAttestationMutex.Unlock() + if stub != nil { + return stub(arg1, arg2) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *BlockVerifier) VerifyBlockAttestationCallCount() int { + fake.verifyBlockAttestationMutex.RLock() + defer fake.verifyBlockAttestationMutex.RUnlock() + return len(fake.verifyBlockAttestationArgsForCall) +} + +func (fake *BlockVerifier) VerifyBlockAttestationCalls(stub func(string, *commona.Block) error) { + fake.verifyBlockAttestationMutex.Lock() + defer fake.verifyBlockAttestationMutex.Unlock() + fake.VerifyBlockAttestationStub = stub +} + +func (fake *BlockVerifier) VerifyBlockAttestationArgsForCall(i int) (string, *commona.Block) { + fake.verifyBlockAttestationMutex.RLock() + defer fake.verifyBlockAttestationMutex.RUnlock() + argsForCall := fake.verifyBlockAttestationArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2 +} + +func (fake *BlockVerifier) VerifyBlockAttestationReturns(result1 error) { + fake.verifyBlockAttestationMutex.Lock() + defer fake.verifyBlockAttestationMutex.Unlock() + fake.VerifyBlockAttestationStub = nil + fake.verifyBlockAttestationReturns = struct { + result1 error + }{result1} +} + +func (fake *BlockVerifier) VerifyBlockAttestationReturnsOnCall(i int, result1 error) { + fake.verifyBlockAttestationMutex.Lock() + defer fake.verifyBlockAttestationMutex.Unlock() + fake.VerifyBlockAttestationStub = nil + if fake.verifyBlockAttestationReturnsOnCall == nil { + fake.verifyBlockAttestationReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.verifyBlockAttestationReturnsOnCall[i] = struct { + result1 error + }{result1} +} + func (fake *BlockVerifier) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.verifyBlockMutex.RLock() defer fake.verifyBlockMutex.RUnlock() + fake.verifyBlockAttestationMutex.RLock() + defer fake.verifyBlockAttestationMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value diff --git a/internal/pkg/peer/blocksprovider/fake/deliver_streamer.go b/internal/pkg/peer/blocksprovider/fake/deliver_streamer.go index e9fcfbcdbae..853b58ebf78 100644 --- a/internal/pkg/peer/blocksprovider/fake/deliver_streamer.go +++ b/internal/pkg/peer/blocksprovider/fake/deliver_streamer.go @@ -36,15 +36,16 @@ func (fake *DeliverStreamer) Deliver(arg1 context.Context, arg2 *grpc.ClientConn arg1 context.Context arg2 *grpc.ClientConn }{arg1, arg2}) + stub := fake.DeliverStub + fakeReturns := fake.deliverReturns fake.recordInvocation("Deliver", []interface{}{arg1, arg2}) fake.deliverMutex.Unlock() - if fake.DeliverStub != nil { - return fake.DeliverStub(arg1, arg2) + if stub != nil { + return stub(arg1, arg2) } if specificReturn { return ret.result1, ret.result2 } - fakeReturns := fake.deliverReturns return fakeReturns.result1, fakeReturns.result2 } diff --git a/internal/pkg/peer/blocksprovider/fake/dialer.go b/internal/pkg/peer/blocksprovider/fake/dialer.go index f0053988e56..f00434b61c2 100644 --- a/internal/pkg/peer/blocksprovider/fake/dialer.go +++ b/internal/pkg/peer/blocksprovider/fake/dialer.go @@ -39,15 +39,16 @@ func (fake *Dialer) Dial(arg1 string, arg2 [][]byte) (*grpc.ClientConn, error) { arg1 string arg2 [][]byte }{arg1, arg2Copy}) + stub := fake.DialStub + fakeReturns := fake.dialReturns fake.recordInvocation("Dial", []interface{}{arg1, arg2Copy}) fake.dialMutex.Unlock() - if fake.DialStub != nil { - return fake.DialStub(arg1, arg2) + if stub != nil { + return stub(arg1, arg2) } if specificReturn { return ret.result1, ret.result2 } - fakeReturns := fake.dialReturns return fakeReturns.result1, fakeReturns.result2 } diff --git a/internal/pkg/peer/blocksprovider/fake/gossip_service_adapter.go b/internal/pkg/peer/blocksprovider/fake/gossip_service_adapter.go index c5a63d991ed..37630f81c2f 100644 --- a/internal/pkg/peer/blocksprovider/fake/gossip_service_adapter.go +++ b/internal/pkg/peer/blocksprovider/fake/gossip_service_adapter.go @@ -37,15 +37,16 @@ func (fake *GossipServiceAdapter) AddPayload(arg1 string, arg2 *gossip.Payload) arg1 string arg2 *gossip.Payload }{arg1, arg2}) + stub := fake.AddPayloadStub + fakeReturns := fake.addPayloadReturns fake.recordInvocation("AddPayload", []interface{}{arg1, arg2}) fake.addPayloadMutex.Unlock() - if fake.AddPayloadStub != nil { - return fake.AddPayloadStub(arg1, arg2) + if stub != nil { + return stub(arg1, arg2) } if specificReturn { return ret.result1 } - fakeReturns := fake.addPayloadReturns return fakeReturns.result1 } @@ -96,9 +97,10 @@ func (fake *GossipServiceAdapter) Gossip(arg1 *gossip.GossipMessage) { fake.gossipArgsForCall = append(fake.gossipArgsForCall, struct { arg1 *gossip.GossipMessage }{arg1}) + stub := fake.GossipStub fake.recordInvocation("Gossip", []interface{}{arg1}) fake.gossipMutex.Unlock() - if fake.GossipStub != nil { + if stub != nil { fake.GossipStub(arg1) } } diff --git a/internal/pkg/peer/blocksprovider/fake/ledger_info.go b/internal/pkg/peer/blocksprovider/fake/ledger_info.go index 1ea37fdee7a..a2ffb8bdc2e 100644 --- a/internal/pkg/peer/blocksprovider/fake/ledger_info.go +++ b/internal/pkg/peer/blocksprovider/fake/ledger_info.go @@ -29,15 +29,16 @@ func (fake *LedgerInfo) LedgerHeight() (uint64, error) { ret, specificReturn := fake.ledgerHeightReturnsOnCall[len(fake.ledgerHeightArgsForCall)] fake.ledgerHeightArgsForCall = append(fake.ledgerHeightArgsForCall, struct { }{}) + stub := fake.LedgerHeightStub + fakeReturns := fake.ledgerHeightReturns fake.recordInvocation("LedgerHeight", []interface{}{}) fake.ledgerHeightMutex.Unlock() - if fake.LedgerHeightStub != nil { - return fake.LedgerHeightStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1, ret.result2 } - fakeReturns := fake.ledgerHeightReturns return fakeReturns.result1, fakeReturns.result2 } diff --git a/internal/pkg/peer/blocksprovider/fake/orderer_connection_source.go b/internal/pkg/peer/blocksprovider/fake/orderer_connection_source.go index 8550a8914d3..2921d8f2081 100644 --- a/internal/pkg/peer/blocksprovider/fake/orderer_connection_source.go +++ b/internal/pkg/peer/blocksprovider/fake/orderer_connection_source.go @@ -30,15 +30,16 @@ func (fake *OrdererConnectionSource) RandomEndpoint() (*orderers.Endpoint, error ret, specificReturn := fake.randomEndpointReturnsOnCall[len(fake.randomEndpointArgsForCall)] fake.randomEndpointArgsForCall = append(fake.randomEndpointArgsForCall, struct { }{}) + stub := fake.RandomEndpointStub + fakeReturns := fake.randomEndpointReturns fake.recordInvocation("RandomEndpoint", []interface{}{}) fake.randomEndpointMutex.Unlock() - if fake.RandomEndpointStub != nil { - return fake.RandomEndpointStub() + if stub != nil { + return stub() } if specificReturn { return ret.result1, ret.result2 } - fakeReturns := fake.randomEndpointReturns return fakeReturns.result1, fakeReturns.result2 }