Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions epochStart/bootstrap/disabled/disabledValidityAttester.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func (v *validityAttester) CheckBlockAgainstRoundHandler(_ data.HeaderHandler) e
return nil
}

// CheckBlockAgainstWhitelist -
func (v *validityAttester) CheckBlockAgainstWhitelist(_ process.InterceptedData) bool {
// CheckAgainstWhitelist -
func (v *validityAttester) CheckAgainstWhitelist(_ process.InterceptedData) bool {
return false
}

Expand Down
10 changes: 5 additions & 5 deletions factory/mock/blockTrackerStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type BlockTrackerStub struct {
CheckProofAgainstRoundHandlerCalled func(proof data.HeaderProofHandler) error
CheckBlockAgainstFinalCalled func(headerHandler data.HeaderHandler) error
CheckProofAgainstFinalCalled func(proof data.HeaderProofHandler) error
CheckBlockAgainstWhitelistCalled func(interceptedData process.InterceptedData) bool
CheckAgainstWhitelistCalled func(interceptedData process.InterceptedData) bool
CleanupHeadersBehindNonceCalled func(shardID uint32, selfNotarizedNonce uint64, crossNotarizedNonce uint64)
ComputeLongestChainCalled func(shardID uint32, header data.HeaderHandler) ([]data.HeaderHandler, [][]byte)
ComputeLongestMetaChainFromLastNotarizedCalled func() ([]data.HeaderHandler, [][]byte, error)
Expand Down Expand Up @@ -99,10 +99,10 @@ func (bts *BlockTrackerStub) CheckProofAgainstRoundHandler(proof data.HeaderProo
return nil
}

// CheckBlockAgainstWhitelist -
func (bts *BlockTrackerStub) CheckBlockAgainstWhitelist(interceptedData process.InterceptedData) bool {
if bts.CheckBlockAgainstWhitelistCalled != nil {
return bts.CheckBlockAgainstWhitelistCalled(interceptedData)
// CheckAgainstWhitelist -
func (bts *BlockTrackerStub) CheckAgainstWhitelist(interceptedData process.InterceptedData) bool {
if bts.CheckAgainstWhitelistCalled != nil {
return bts.CheckAgainstWhitelistCalled(interceptedData)
}

return false
Expand Down
10 changes: 5 additions & 5 deletions integrationTests/mock/blockTrackerStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type BlockTrackerStub struct {
CheckProofAgainstFinalCalled func(proof data.HeaderProofHandler) error
CheckBlockAgainstRoundHandlerCalled func(headerHandler data.HeaderHandler) error
CheckProofAgainstRoundHandlerCalled func(proof data.HeaderProofHandler) error
CheckBlockAgainstWhitelistCalled func(interceptedData process.InterceptedData) bool
CheckAgainstWhitelistCalled func(interceptedData process.InterceptedData) bool
CleanupHeadersBehindNonceCalled func(shardID uint32, selfNotarizedNonce uint64, crossNotarizedNonce uint64)
ComputeLongestChainCalled func(shardID uint32, header data.HeaderHandler) ([]data.HeaderHandler, [][]byte)
ComputeLongestMetaChainFromLastNotarizedCalled func() ([]data.HeaderHandler, [][]byte, error)
Expand Down Expand Up @@ -100,10 +100,10 @@ func (bts *BlockTrackerStub) CheckProofAgainstRoundHandler(proof data.HeaderProo
return nil
}

// CheckBlockAgainstWhitelist -
func (bts *BlockTrackerStub) CheckBlockAgainstWhitelist(interceptedData process.InterceptedData) bool {
if bts.CheckBlockAgainstWhitelistCalled != nil {
return bts.CheckBlockAgainstWhitelistCalled(interceptedData)
// CheckAgainstWhitelist -
func (bts *BlockTrackerStub) CheckAgainstWhitelist(interceptedData process.InterceptedData) bool {
if bts.CheckAgainstWhitelistCalled != nil {
return bts.CheckAgainstWhitelistCalled(interceptedData)
}

return false
Expand Down
10 changes: 5 additions & 5 deletions node/mock/blockTrackerStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type BlockTrackerStub struct {
AddSelfNotarizedHeaderCalled func(shardID uint32, selfNotarizedHeader data.HeaderHandler, selfNotarizedHeaderHash []byte)
CheckBlockAgainstRoundHandlerCalled func(headerHandler data.HeaderHandler) error
CheckBlockAgainstFinalCalled func(headerHandler data.HeaderHandler) error
CheckBlockAgainstWhitelistCalled func(interceptedData process.InterceptedData) bool
CheckAgainstWhitelistCalled func(interceptedData process.InterceptedData) bool
CleanupHeadersBehindNonceCalled func(shardID uint32, selfNotarizedNonce uint64, crossNotarizedNonce uint64)
ComputeLongestChainCalled func(shardID uint32, header data.HeaderHandler) ([]data.HeaderHandler, [][]byte)
ComputeLongestMetaChainFromLastNotarizedCalled func() ([]data.HeaderHandler, [][]byte, error)
Expand Down Expand Up @@ -97,10 +97,10 @@ func (bts *BlockTrackerStub) CheckBlockAgainstFinal(headerHandler data.HeaderHan
return nil
}

// CheckBlockAgainstWhitelist -
func (bts *BlockTrackerStub) CheckBlockAgainstWhitelist(interceptedData process.InterceptedData) bool {
if bts.CheckBlockAgainstWhitelistCalled != nil {
return bts.CheckBlockAgainstWhitelistCalled(interceptedData)
// CheckAgainstWhitelist -
func (bts *BlockTrackerStub) CheckAgainstWhitelist(interceptedData process.InterceptedData) bool {
if bts.CheckAgainstWhitelistCalled != nil {
return bts.CheckAgainstWhitelistCalled(interceptedData)
}

return false
Expand Down
2 changes: 1 addition & 1 deletion process/block/interceptedBlocks/interceptedBlockHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (inHdr *InterceptedHeader) integrity() error {
return err
}

if !inHdr.validityAttester.CheckBlockAgainstWhitelist(inHdr) {
if !inHdr.validityAttester.CheckAgainstWhitelist(inHdr) {
err = inHdr.validityAttester.CheckBlockAgainstFinal(inHdr.HeaderHandler())
if err != nil {
return err
Expand Down
8 changes: 5 additions & 3 deletions process/block/interceptedBlocks/interceptedEquivalentProof.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,11 @@ func (iep *interceptedEquivalentProof) CheckValidity() error {
return err
}

err = iep.validityAttester.CheckProofAgainstFinal(iep.proof)
if err != nil {
return err
if !iep.validityAttester.CheckAgainstWhitelist(iep) {
err = iep.validityAttester.CheckProofAgainstFinal(iep.proof)
if err != nil {
return err
}
}

err = iep.validityAttester.CheckProofAgainstRoundHandler(iep.proof)
Expand Down
38 changes: 38 additions & 0 deletions process/block/interceptedBlocks/interceptedEquivalentProof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,44 @@ func TestInterceptedEquivalentProof_CheckValidity(t *testing.T) {
err = iep.CheckValidity()
require.Equal(t, expectedErr, err)
})
t.Run("whitelisted proof should bypass CheckProofAgainstFinal", func(t *testing.T) {
t.Parallel()

args := createMockArgInterceptedEquivalentProof()
args.ValidityAttester = &processMock.ValidityAttesterStub{
CheckAgainstWhitelistCalled: func(interceptedData process.InterceptedData) bool {
return true
},
CheckProofAgainstFinalCalled: func(proof data.HeaderProofHandler) error {
return expectedErr
},
}

iep, err := NewInterceptedEquivalentProof(args)
require.NoError(t, err)

err = iep.CheckValidity()
require.NoError(t, err)
})
t.Run("whitelisted proof should still enforce round handler check", func(t *testing.T) {
t.Parallel()

args := createMockArgInterceptedEquivalentProof()
args.ValidityAttester = &processMock.ValidityAttesterStub{
CheckAgainstWhitelistCalled: func(interceptedData process.InterceptedData) bool {
return true
},
CheckProofAgainstRoundHandlerCalled: func(proof data.HeaderProofHandler) error {
return expectedErr
},
}

iep, err := NewInterceptedEquivalentProof(args)
require.NoError(t, err)

err = iep.CheckValidity()
require.Equal(t, expectedErr, err)
})
t.Run("already exiting proof should error", func(t *testing.T) {
t.Parallel()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (imh *InterceptedMetaHeader) CheckValidity() error {
return err
}

if !imh.validityAttester.CheckBlockAgainstWhitelist(imh) {
if !imh.validityAttester.CheckAgainstWhitelist(imh) {
err = imh.validityAttester.CheckBlockAgainstFinal(imh.HeaderHandler())
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions process/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ type BlockTracker interface {
AddTrackedHeader(header data.HeaderHandler, hash []byte)
CheckBlockAgainstFinal(headerHandler data.HeaderHandler) error
CheckBlockAgainstRoundHandler(headerHandler data.HeaderHandler) error
CheckBlockAgainstWhitelist(interceptedData InterceptedData) bool
CheckAgainstWhitelist(interceptedData InterceptedData) bool
CheckProofAgainstFinal(proof data.HeaderProofHandler) error
CheckProofAgainstRoundHandler(proof data.HeaderProofHandler) error
CleanupHeadersBehindNonce(shardID uint32, selfNotarizedNonce uint64, crossNotarizedNonce uint64)
Expand Down Expand Up @@ -1163,7 +1163,7 @@ type EpochStartSystemSCProcessor interface {
type ValidityAttester interface {
CheckBlockAgainstFinal(headerHandler data.HeaderHandler) error
CheckBlockAgainstRoundHandler(headerHandler data.HeaderHandler) error
CheckBlockAgainstWhitelist(interceptedData InterceptedData) bool
CheckAgainstWhitelist(interceptedData InterceptedData) bool
CheckProofAgainstFinal(proof data.HeaderProofHandler) error
CheckProofAgainstRoundHandler(proof data.HeaderProofHandler) error
IsInterfaceNil() bool
Expand Down
10 changes: 5 additions & 5 deletions process/mock/blockTrackerMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type BlockTrackerMock struct {
CheckProofAgainstFinalCalled func(proof data.HeaderProofHandler) error
CheckBlockAgainstRoundHandlerCalled func(headerHandler data.HeaderHandler) error
CheckProofAgainstRoundHandlerCalled func(proof data.HeaderProofHandler) error
CheckBlockAgainstWhitelistCalled func(interceptedData process.InterceptedData) bool
CheckAgainstWhitelistCalled func(interceptedData process.InterceptedData) bool
CleanupHeadersBehindNonceCalled func(shardID uint32, selfNotarizedNonce uint64, crossNotarizedNonce uint64)
ComputeLongestChainCalled func(shardID uint32, header data.HeaderHandler) ([]data.HeaderHandler, [][]byte)
ComputeLongestMetaChainFromLastNotarizedCalled func() ([]data.HeaderHandler, [][]byte, error)
Expand Down Expand Up @@ -204,10 +204,10 @@ func (btm *BlockTrackerMock) CheckProofAgainstRoundHandler(proof data.HeaderProo
return nil
}

// CheckBlockAgainstWhitelist -
func (btm *BlockTrackerMock) CheckBlockAgainstWhitelist(interceptedData process.InterceptedData) bool {
if btm.CheckBlockAgainstWhitelistCalled != nil {
return btm.CheckBlockAgainstWhitelistCalled(interceptedData)
// CheckAgainstWhitelist -
func (btm *BlockTrackerMock) CheckAgainstWhitelist(interceptedData process.InterceptedData) bool {
if btm.CheckAgainstWhitelistCalled != nil {
return btm.CheckAgainstWhitelistCalled(interceptedData)
}

return false
Expand Down
10 changes: 5 additions & 5 deletions process/mock/finalityAttesterStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type ValidityAttesterStub struct {
CheckBlockAgainstRoundHandlerCalled func(headerHandler data.HeaderHandler) error
CheckBlockAgainstFinalCalled func(headerHandler data.HeaderHandler) error
CheckBlockAgainstWhitelistCalled func(interceptedData process.InterceptedData) bool
CheckAgainstWhitelistCalled func(interceptedData process.InterceptedData) bool
CheckProofAgainstFinalCalled func(proof data.HeaderProofHandler) error
CheckProofAgainstRoundHandlerCalled func(proof data.HeaderProofHandler) error
}
Expand All @@ -33,10 +33,10 @@ func (vas *ValidityAttesterStub) CheckBlockAgainstFinal(headerHandler data.Heade
return nil
}

// CheckBlockAgainstWhitelist -
func (vas *ValidityAttesterStub) CheckBlockAgainstWhitelist(interceptedData process.InterceptedData) bool {
if vas.CheckBlockAgainstWhitelistCalled != nil {
return vas.CheckBlockAgainstWhitelistCalled(interceptedData)
// CheckAgainstWhitelist -
func (vas *ValidityAttesterStub) CheckAgainstWhitelist(interceptedData process.InterceptedData) bool {
if vas.CheckAgainstWhitelistCalled != nil {
return vas.CheckAgainstWhitelistCalled(interceptedData)
}

return false
Expand Down
8 changes: 3 additions & 5 deletions process/track/baseBlockTrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,7 @@ func (bbt *baseBlockTrack) CheckProofAgainstFinal(proof data.HeaderProofHandler)
return process.ErrNilHeaderProof
}

// TODO: need to fix the condition for proofs
// return bbt.checkAgainstFinal(proof.GetHeaderShardId(), proof.GetHeaderRound(), proof.GetHeaderNonce())
return nil
return bbt.checkAgainstFinal(proof.GetHeaderShardId(), proof.GetHeaderRound(), proof.GetHeaderNonce())
}

func (bbt *baseBlockTrack) checkAgainstFinal(shardID uint32, round uint64, nonce uint64) error {
Expand Down Expand Up @@ -566,8 +564,8 @@ func (bbt *baseBlockTrack) getFinalHeader(shardID uint32) (data.HeaderHandler, [
return bbt.selfNotarizer.GetFirstNotarizedHeader(shardID)
}

// CheckBlockAgainstWhitelist returns if the provided intercepted data (blocks) is whitelisted or not
func (bbt *baseBlockTrack) CheckBlockAgainstWhitelist(interceptedData process.InterceptedData) bool {
// CheckAgainstWhitelist returns if the provided intercepted data is whitelisted or not
func (bbt *baseBlockTrack) CheckAgainstWhitelist(interceptedData process.InterceptedData) bool {
return bbt.whitelistHandler.IsWhiteListed(interceptedData)
}

Expand Down
Loading