Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate proof check on sync #6501

Merged
merged 36 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
85dca04
add proof signature check in header check
ssd04 Sep 25, 2024
712e0da
wait for confirmation block in epoch start block syncer
ssd04 Sep 25, 2024
4bddfce
fix epoch start meta block syncer tests
ssd04 Sep 25, 2024
d398385
Merge branch 'feat/equivalent-messages' into integrate-proof-check-on…
ssd04 Oct 3, 2024
66316b2
added proofs pool in process sync
ssd04 Oct 3, 2024
225945f
integrate proofs pool in interceptors factory
ssd04 Oct 4, 2024
1cc05a0
Merge branch 'feat/equivalent-messages' into integrate-proof-check-on…
ssd04 Oct 4, 2024
c244eca
fix epoch start bootstrap process tests
ssd04 Oct 4, 2024
d2598ff
refactor to use flag activation in epoch start meta block processor
ssd04 Oct 5, 2024
d4886f4
add todo for meta block sync duplicated code
ssd04 Oct 5, 2024
58eeb1e
unit tests for flow with equivalent proofs
ssd04 Oct 7, 2024
3813ce8
process block only if there is a proof
ssd04 Oct 7, 2024
ed9fbba
fix comment
ssd04 Oct 14, 2024
4b03649
add log trace check on display
ssd04 Oct 21, 2024
80f1ca3
remove debug prints
ssd04 Oct 21, 2024
47746d5
Merge branch 'feat/equivalent-messages' into integrate-proof-check-on…
ssd04 Oct 21, 2024
12d156a
add proofs pool subscribers
ssd04 Oct 24, 2024
176e9a9
fix linter issue
ssd04 Oct 24, 2024
fd736e6
added nil check unit tests
ssd04 Oct 24, 2024
20ea2ff
handle equivalent proof separatelly
ssd04 Nov 22, 2024
ba15d49
integration test for sync with equivalent proofs
ssd04 Nov 22, 2024
d7d94ab
update check on sync with equivalent proofs test
ssd04 Nov 25, 2024
a389ce3
fix linter issue
ssd04 Nov 25, 2024
c87d855
added more unit tests for handling equivalent proof
ssd04 Nov 26, 2024
38f273b
Merge branch 'feat/equivalent-messages' into integrate-proof-check-on…
ssd04 Dec 9, 2024
d5b069f
Merge branch 'feat/equivalent-messages' into integrate-proof-check-on…
AdoAdoAdo Dec 10, 2024
dd70b0d
Merge branch 'feat/equivalent-messages' into integrate-proof-check-on…
ssd04 Dec 16, 2024
1715ed0
Merge branch 'feat/equivalent-messages' into integrate-proof-check-on…
ssd04 Dec 17, 2024
8a95e05
fix conflicts
ssd04 Dec 17, 2024
89a246e
added flag for proofs check in header intercetor
ssd04 Dec 17, 2024
cb82037
remove todo in sync process for proofs
ssd04 Dec 17, 2024
87a635e
remove accumulation maps for epoch start confirmation block
ssd04 Dec 17, 2024
44ab7fa
rename chan
ssd04 Dec 17, 2024
555ea3d
more fixes after review
ssd04 Dec 17, 2024
ebb3fc3
added more unit tests on handling equivalent proofs on sync
ssd04 Dec 17, 2024
39af8f1
check for already existing equivalent proof
ssd04 Dec 17, 2024
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
33 changes: 30 additions & 3 deletions dataRetriever/dataPool/proofsCache/proofsPool.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package proofscache

import (
"encoding/hex"
"fmt"
"sync"

Expand All @@ -14,12 +15,16 @@ var log = logger.GetOrCreate("dataRetriever/proofscache")
type proofsPool struct {
mutCache sync.RWMutex
cache map[uint32]*proofsCache

mutAddedProofHandlers sync.RWMutex
addedProofHandlers []func(headerProof data.HeaderProofHandler)
}

// NewProofsPool creates a new proofs pool component
func NewProofsPool() *proofsPool {
return &proofsPool{
cache: make(map[uint32]*proofsCache),
cache: make(map[uint32]*proofsCache),
addedProofHandlers: make([]func(headerProof data.HeaderProofHandler), 0),
}
}

Expand All @@ -36,8 +41,7 @@ func (pp *proofsPool) AddProof(

hasProof := pp.HasProof(shardID, headerHash)
if hasProof {
log.Trace("there was already a valid proof for header, headerHash: %s", headerHash)
return nil
return fmt.Errorf("there was already a valid proof for header, headerHash: %s", hex.EncodeToString(headerHash))
}

pp.mutCache.Lock()
Expand All @@ -59,9 +63,20 @@ func (pp *proofsPool) AddProof(

proofsPerShard.addProof(headerProof)

pp.callAddedProofHandlers(headerProof)

return nil
}

func (pp *proofsPool) callAddedProofHandlers(headerProof data.HeaderProofHandler) {
AdoAdoAdo marked this conversation as resolved.
Show resolved Hide resolved
pp.mutAddedProofHandlers.RLock()
defer pp.mutAddedProofHandlers.RUnlock()

for _, handler := range pp.addedProofHandlers {
go handler(headerProof)
}
}

// CleanupProofsBehindNonce will cleanup proofs from pool based on nonce
func (pp *proofsPool) CleanupProofsBehindNonce(shardID uint32, nonce uint64) error {
if nonce == 0 {
Expand Down Expand Up @@ -120,6 +135,18 @@ func (pp *proofsPool) HasProof(
return err == nil
}

// RegisterHandler registers a new handler to be called when a new data is added
func (pp *proofsPool) RegisterHandler(handler func(headerProof data.HeaderProofHandler)) {
if handler == nil {
log.Error("attempt to register a nil handler to proofs pool")
return
}

pp.mutAddedProofHandlers.Lock()
pp.addedProofHandlers = append(pp.addedProofHandlers, handler)
pp.mutAddedProofHandlers.Unlock()
}

// IsInterfaceNil returns true if there is no value under the interface
func (pp *proofsPool) IsInterfaceNil() bool {
return pp == nil
Expand Down
29 changes: 28 additions & 1 deletion dataRetriever/dataPool/proofsCache/proofsPool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync/atomic"
"testing"

"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
proofscache "github.com/multiversx/mx-chain-go/dataRetriever/dataPool/proofsCache"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -81,6 +82,28 @@ func TestProofsPool_ShouldWork(t *testing.T) {
require.Equal(t, proof4, proof)
}

func TestProofsPool_RegisterHandler(t *testing.T) {
t.Parallel()

pp := proofscache.NewProofsPool()

wasCalled := false
wg := sync.WaitGroup{}
wg.Add(1)
handler := func(proof data.HeaderProofHandler) {
wasCalled = true
wg.Done()
}
pp.RegisterHandler(nil)
pp.RegisterHandler(handler)

_ = pp.AddProof(generateProof())

wg.Wait()

assert.True(t, wasCalled)
}

func TestProofsPool_Concurrency(t *testing.T) {
t.Parallel()

Expand All @@ -95,7 +118,7 @@ func TestProofsPool_Concurrency(t *testing.T) {

for i := 0; i < numOperations; i++ {
go func(idx int) {
switch idx % 5 {
switch idx % 6 {
case 0, 1, 2:
_ = pp.AddProof(generateProof())
case 3:
Expand All @@ -105,6 +128,10 @@ func TestProofsPool_Concurrency(t *testing.T) {
}
case 4:
_ = pp.CleanupProofsBehindNonce(generateRandomShardID(), generateRandomNonce())
case 5:
handler := func(proof data.HeaderProofHandler) {
}
pp.RegisterHandler(handler)
default:
assert.Fail(t, "should have not beed called")
}
Expand Down
3 changes: 3 additions & 0 deletions epochStart/bootstrap/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ func checkArguments(args ArgsEpochStartBootstrap) error {
if check.IfNil(args.NodesCoordinatorRegistryFactory) {
return fmt.Errorf("%s: %w", baseErrorMessage, nodesCoordinator.ErrNilNodesCoordinatorRegistryFactory)
}
if check.IfNil(args.EnableEpochsHandler) {
return fmt.Errorf("%s: %w", baseErrorMessage, epochStart.ErrNilEnableEpochsHandler)
}

return nil
}
Loading
Loading