forked from erigontech/erigon
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag 'v2.58.2' into release/v2.58.2
- Loading branch information
Showing
483 changed files
with
122,631 additions
and
25,787 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: QA - Clean exit (block downloading) | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'release/**' | ||
pull_request: | ||
branches: | ||
- devel | ||
- 'release/**' | ||
types: | ||
- ready_for_review | ||
|
||
jobs: | ||
long-running-test: | ||
runs-on: self-hosted | ||
env: | ||
ERIGON_REFERENCE_DATA_DIR: /opt/erigon-release/datadir | ||
ERIGON_TESTBED_DATA_DIR: /opt/erigon-testbed/datadir | ||
WORKING_TIME_SECONDS: 600 | ||
|
||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.21' | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' | ||
|
||
#- name: Install dependencies | ||
# run: | | ||
# sudo apt-get update | ||
# sudo apt-get install -y build-essential make gcc | ||
|
||
- name: Restore Erigon Testbed Data Directory | ||
run: | | ||
rm -rf $ERIGON_TESTBED_DATA_DIR/chaindata | ||
rsync -a --delete $ERIGON_REFERENCE_DATA_DIR/ $ERIGON_TESTBED_DATA_DIR/ | ||
- name: Clean Erigon Build Directory | ||
run: | | ||
make clean | ||
- name: Build Erigon | ||
run: | | ||
make erigon | ||
working-directory: ${{ github.workspace }} | ||
|
||
- name: Run Erigon, send ctrl-c and check for clean exiting | ||
run: | | ||
# Run Erigon, send ctrl-c and check logs | ||
python3 ${{ github.workspace }}/../../../../erigon-qa/test_system/qa-tests/clean-exit/run_and_check_clean_exit.py ${{ github.workspace }}/build/bin $ERIGON_TESTBED_DATA_DIR $WORKING_TIME_SECONDS | ||
# Capture monitoring script exit status | ||
monitoring_exit_status=$? | ||
|
||
# Clean up Erigon process if it's still running | ||
if kill -0 $ERIGON_PID 2> /dev/null; then | ||
echo "Terminating Erigon" | ||
kill $ERIGON_PID | ||
wait $ERIGON_PID | ||
else | ||
echo "Erigon has already terminated" | ||
fi | ||
|
||
# Check monitoring script exit status | ||
if [ $monitoring_exit_status -eq 0 ]; then | ||
echo "Monitoring completed successfully" | ||
else | ||
echo "Error detected in Erigon logs or monitoring script exited unexpectedly" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package beaconevents | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/google/uuid" | ||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
type Subscription struct { | ||
id string | ||
topics map[string]struct{} | ||
cb func(topic string, item any) | ||
} | ||
|
||
type EventName string | ||
|
||
// Emitters creates pub/sub connection | ||
type Emitters struct { | ||
cbs map[string]*Subscription | ||
mu sync.RWMutex | ||
} | ||
|
||
func NewEmitters() *Emitters { | ||
return &Emitters{ | ||
cbs: map[string]*Subscription{}, | ||
} | ||
} | ||
|
||
// publish to all subscribers. each callback is run in a separate goroutine | ||
func (e *Emitters) Publish(s string, a any) { | ||
// forward gossip object | ||
e.mu.Lock() | ||
values := make([]*Subscription, 0, len(e.cbs)) | ||
for _, v := range e.cbs { | ||
values = append(values, v) | ||
} | ||
e.mu.Unlock() | ||
|
||
egg := errgroup.Group{} | ||
for idx := range values { | ||
v := values[idx] | ||
exec := func() error { v.cb(s, a); return nil } | ||
if _, ok := v.topics["*"]; ok { | ||
egg.Go(exec) | ||
} else if _, ok := v.topics[s]; ok { | ||
egg.Go(exec) | ||
} | ||
} | ||
egg.Wait() | ||
} | ||
|
||
// subscribe with callback. call the returned cancelfunc to unregister the callback | ||
// publish will block until all callbacks for the message are resolved | ||
func (e *Emitters) Subscribe(topics []string, cb func(topic string, item any)) (func(), error) { | ||
subid := uuid.New().String() | ||
sub := &Subscription{ | ||
id: subid, | ||
topics: map[string]struct{}{}, | ||
cb: cb, | ||
} | ||
for _, v := range topics { | ||
sub.topics[v] = struct{}{} | ||
} | ||
e.cbs[subid] = sub | ||
return func() { | ||
e.mu.Lock() | ||
defer e.mu.Unlock() | ||
delete(e.cbs, subid) | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package beaconevents_test | ||
|
||
import ( | ||
"sync/atomic" | ||
"testing" | ||
|
||
"github.com/ledgerwatch/erigon/cl/beacon/beaconevents" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestEmitterSet(t *testing.T) { | ||
e := beaconevents.NewEmitters() | ||
var called int | ||
e.Subscribe([]string{"set"}, func(topic string, item any) { | ||
require.EqualValues(t, "set", topic) | ||
require.EqualValues(t, "hello", item.(string)) | ||
called = called + 1 | ||
}) | ||
e.Publish("set", "hello") | ||
require.EqualValues(t, 1, called) | ||
} | ||
func TestEmitterFilters(t *testing.T) { | ||
e := beaconevents.NewEmitters() | ||
var a atomic.Int64 | ||
var b atomic.Int64 | ||
var ab atomic.Int64 | ||
var wild atomic.Int64 | ||
e.Subscribe([]string{"a"}, func(topic string, item any) { | ||
require.EqualValues(t, topic, item.(string)) | ||
a.Add(1) | ||
}) | ||
e.Subscribe([]string{"b"}, func(topic string, item any) { | ||
require.EqualValues(t, topic, item.(string)) | ||
b.Add(1) | ||
}) | ||
e.Subscribe([]string{"a", "b"}, func(topic string, item any) { | ||
require.EqualValues(t, topic, item.(string)) | ||
ab.Add(1) | ||
}) | ||
e.Subscribe([]string{"*"}, func(topic string, item any) { | ||
require.EqualValues(t, topic, item.(string)) | ||
wild.Add(1) | ||
}) | ||
|
||
e.Publish("a", "a") | ||
e.Publish("b", "b") | ||
e.Publish("b", "b") | ||
e.Publish("c", "c") | ||
|
||
require.EqualValues(t, 1, a.Load()) | ||
require.EqualValues(t, 2, b.Load()) | ||
require.EqualValues(t, 3, ab.Load()) | ||
require.EqualValues(t, 4, wild.Load()) | ||
} |
Oops, something went wrong.