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

Chore/check events from logs #448

Merged
merged 3 commits into from
Oct 4, 2024
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ This repo does not accept issues. Please use <https://github.com/palomachain/pal
### To get the latest prebuilt `pigeon` binary

```shell
wget -O - https://github.com/palomachain/pigeon/releases/download/v2.3.0/pigeon_Linux_x86_64.tar.gz | \
wget -O - https://github.com/palomachain/pigeon/releases/download/v2.3.1/pigeon_Linux_x86_64.tar.gz | \
sudo tar -C /usr/local/bin -xvzf - pigeon
sudo chmod +x /usr/local/bin/pigeon

Expand All @@ -94,7 +94,7 @@ mkdir ~/.pigeon
```shell
git clone https://github.com/palomachain/pigeon.git
cd pigeon
git checkout v2.3.0
git checkout v2.3.1
make build
sudo mv ./build/pigeon /usr/local/bin/pigeon

Expand Down
114 changes: 73 additions & 41 deletions chain/evm/compass.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,56 +1022,24 @@ func (t *compass) getLogs(
return logs, filter.ToBlock.Uint64(), err
}

func (t *compass) GetSkywayEvents(
func (t *compass) getEvents(
ctx context.Context,
orchestrator string,
logger *logrus.Entry,
lastSkywayNonce uint64,
logs []ethtypes.Log,
) ([]chain.SkywayEventer, error) {
logger := liblog.WithContext(ctx)

logger.Debug("Querying compass events")

blocks, err := t.paloma.QueryUnobservedBlocksByValidator(ctx, t.ChainReferenceID, orchestrator)
if err != nil {
logger.WithError(err).Warn("Failed to query unobserved blocks")
return nil, err
if len(logs) == 0 {
return nil, nil
}

var logs []ethtypes.Log
var toBlock uint64

if len(blocks) == 0 {
logs, toBlock, err = t.getLogs(ctx, logger, 0, 0)
if err != nil {
return nil, err
}
} else {
var moreLogs []ethtypes.Log
for i := range blocks {
logger.WithField("block", blocks[i]).
Debug("Getting logs from block")

moreLogs, toBlock, err = t.getLogs(ctx, logger, blocks[i], blocks[i])
if err != nil {
return nil, err
}

logs = slices.Concat(logs, moreLogs)
}
}

lastSkywayNonce, err := t.paloma.QueryLastObservedSkywayNonceByAddr(ctx, t.ChainReferenceID, orchestrator)
if err != nil {
logger.WithError(err).Warn("Failed to query last observed nonce")
return nil, err
}
var events []chain.SkywayEventer
var evt chain.SkywayEventer
var err error

logger.WithField("skwyway_nonce", lastSkywayNonce).
WithField("logs", len(logs)).
Debug("Ready to parse events")

var events []chain.SkywayEventer
var evt chain.SkywayEventer

for _, ethLog := range logs {
switch ethLog.Topics[0] {
case nodeSaleEvent:
Expand Down Expand Up @@ -1103,6 +1071,70 @@ func (t *compass) GetSkywayEvents(
events = append(events, evt)
}

return events, nil
}

func (t *compass) GetSkywayEvents(
ctx context.Context,
orchestrator string,
) ([]chain.SkywayEventer, error) {
logger := liblog.WithContext(ctx)

logger.Debug("Querying compass events")

lastSkywayNonce, err := t.paloma.QueryLastObservedSkywayNonceByAddr(ctx, t.ChainReferenceID, orchestrator)
if err != nil {
logger.WithError(err).Warn("Failed to query last observed nonce")
return nil, err
}

blocks, err := t.paloma.QueryUnobservedBlocksByValidator(ctx, t.ChainReferenceID, orchestrator)
if err != nil {
logger.WithError(err).Warn("Failed to query unobserved blocks")
return nil, err
}

var logs []ethtypes.Log
var toBlock uint64
var events []chain.SkywayEventer

if len(blocks) > 0 {
var moreLogs []ethtypes.Log
for i := range blocks {
logger.WithField("block", blocks[i]).
Debug("Getting logs from block")

moreLogs, toBlock, err = t.getLogs(ctx, logger, blocks[i], blocks[i])
if err != nil {
// If there's an error, we just skip this block and move on.
// If it was a block with a legitimate event, we'll eventually
// process it again, otherwise we can just skip it
continue
}

logs = slices.Concat(logs, moreLogs)
}

events, err = t.getEvents(ctx, logger, lastSkywayNonce, logs)
if err != nil {
return nil, err
}
}

if len(events) == 0 {
// If we can't find any logs from the blocks we get from paloma, we
// resume to search from the last seen block
logs, toBlock, err = t.getLogs(ctx, logger, 0, 0)
if err != nil {
return nil, err
}

events, err = t.getEvents(ctx, logger, lastSkywayNonce, logs)
if err != nil {
return nil, err
}
}

t.lastObservedBlockHeight = toBlock

return events, err
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/jarcoal/httpmock v1.3.1
github.com/onsi/ginkgo/v2 v2.19.0
github.com/onsi/gomega v1.33.1
github.com/palomachain/paloma/v2 v2.0.0-20241001160943-eea138b39129
github.com/palomachain/paloma/v2 v2.3.1
github.com/roodeag/arbitrum v0.0.0-20230627104516-b95e4c8ebec0
github.com/rs/xid v1.5.0
github.com/sirupsen/logrus v1.9.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,8 @@ github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnh
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
github.com/palomachain/arb-geth v0.0.0-20230824112942-8e77a580a936 h1:fmQAgxcdYBxCZYczws/uxTVOYHZd4fNrOaoHp35HZMM=
github.com/palomachain/arb-geth v0.0.0-20230824112942-8e77a580a936/go.mod h1:B2H2+2I4UiMR4hvAIaGLyYszNfSTYC8fWIw+kgfuFSQ=
github.com/palomachain/paloma/v2 v2.0.0-20241001160943-eea138b39129 h1:rn1u1p6Ro09uMz1UYJnrjgndSy5Y9rVUunSwCY2OQZs=
github.com/palomachain/paloma/v2 v2.0.0-20241001160943-eea138b39129/go.mod h1:EOa+cqEMAxZXYyvN5BOy0ysDP+3nMDgDUPvIXKzUc4g=
github.com/palomachain/paloma/v2 v2.3.1 h1:wRcRJKiafQbKXXn93qAeg0s4/EBgSs9g5nB/4RC3HLc=
github.com/palomachain/paloma/v2 v2.3.1/go.mod h1:EOa+cqEMAxZXYyvN5BOy0ysDP+3nMDgDUPvIXKzUc4g=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
Expand Down
Loading