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

Generic events sub #36

Merged

Conversation

ggwpez
Copy link
Contributor

@ggwpez ggwpez commented Apr 6, 2021

Add generic event subs in preparation for #19.

@ggwpez ggwpez force-pushed the generic-events-sub branch 2 times, most recently from ed7b697 to d0b692a Compare April 6, 2021 15:03
@ggwpez ggwpez linked an issue Apr 8, 2021 that may be closed by this pull request
@ggwpez ggwpez force-pushed the generic-events-sub branch 3 times, most recently from 8aad187 to 27c6d19 Compare May 19, 2021 09:51
@ggwpez ggwpez marked this pull request as ready for review May 19, 2021 09:54
@ggwpez ggwpez requested a review from matthiasgeihs May 19, 2021 09:54
Copy link
Contributor

@matthiasgeihs matthiasgeihs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is my first review. Please do not force push new changes as long as the review is in progress and the code is not stable yet.

You may consider integrating into this PR already some of the places where the subscription will be used. Otherwise it could happen that we only realize necessary changes later.

backend/ethereum/bindings/peruntoken/PerunToken.go Outdated Show resolved Hide resolved

// Package glue glues together go-perun and go-ethereum.
// It contains generic functionality and can he used even without go-perun.
package glue // import "perun.network/go-perun/backend/ethereum/glue"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package name "glue" is very vague. Use package name "subscription" instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed it to subscription for now. I also wanted to put the reorg-resistant TX stuff in here, then the name subscription would not be enough.

backend/ethereum/glue/eventsub.go Outdated Show resolved Hide resolved
backend/ethereum/glue/eventsub.go Outdated Show resolved Hide resolved
backend/ethereum/glue/eventsub.go Outdated Show resolved Hide resolved
backend/ethereum/glue/eventsub.go Outdated Show resolved Hide resolved
backend/ethereum/glue/eventsub_test.go Outdated Show resolved Hide resolved
@ggwpez
Copy link
Contributor Author

ggwpez commented May 20, 2021

You may consider integrating into this PR already some of the places where the subscription will be used. Otherwise it could happen that we only realize necessary changes later.

Ok i will try it out at some spots where we use it.

@ggwpez
Copy link
Contributor Author

ggwpez commented May 20, 2021

While using the EventSub in the Funder, it seems that the start, end *uint64 pointers that specify the range to query are not easy to use.
I will try to change it just to pastBlocks which is then a relative offset into the past.

@ggwpez
Copy link
Contributor Author

ggwpez commented May 24, 2021

Since the EventSub is using geth functions, we need to check the ChainNotReachableError for every returned error.
The function isChainNotReachableError is in [backend/eth/channel] (and private), which prevents me from importing it, since it would create a cyclic dependency.

So we either make an addictional [backend/eth/channel/error] package or merge the glue package into [backend/eth/channel].
Any other ideas @matthiasgeihs ?

@ggwpez ggwpez requested a review from matthiasgeihs May 25, 2021 10:18
@matthiasgeihs
Copy link
Contributor

Since the EventSub is using geth functions, we need to check the ChainNotReachableError for every returned error.
The function isChainNotReachableError is in [backend/eth/channel] (and private), which prevents me from importing it, since it would create a cyclic dependency.

So we either make an addictional [backend/eth/channel/error] package or merge the glue package into [backend/eth/channel].
Any other ideas @matthiasgeihs ?

I don't understand. Why do we need to check for ChainNotReachableError because of using geth functions? Isn't the error type specific to go-perun?

Anyways, adding a package seems cleaner to me. Or could we maybe check for the error without using a dedicated function?

@ggwpez
Copy link
Contributor Author

ggwpez commented May 25, 2021

I don't understand. Why do we need to check for ChainNotReachableError because of using geth functions? Isn't the error type specific to go-perun?

Ok i meant we need to use checkIsChainNotReachableError in order to make sure that the error is correctly wrapped in the go-perun error type.

Anyways, adding a package seems cleaner to me. Or could we maybe check for the error without using a dedicated function?

The error checking function is like 5 lines of boilerplate code that i would need in 4-5 places.
I will opt for the new [backend/eth/channel/error] package to keep the code more readable.

@ggwpez ggwpez marked this pull request as draft May 28, 2021 08:04
@ggwpez ggwpez force-pushed the generic-events-sub branch 2 times, most recently from ae9c7db to 7734441 Compare May 28, 2021 12:03
@ggwpez ggwpez marked this pull request as ready for review May 28, 2021 12:06
matthiasgeihs
matthiasgeihs previously approved these changes Jun 1, 2021
Copy link
Contributor

@matthiasgeihs matthiasgeihs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only general comments. Looks good.

@@ -184,7 +184,7 @@ func (f *Funder) sendFundingTx(ctx context.Context, request channel.FundingReq,
// nolint: gocritic
if bal == nil || bal.Sign() <= 0 {
f.log.WithFields(log.Fields{"channel": request.Params.ID(), "idx": request.Idx}).Debug("Skipped zero funding.")
} else if alreadyFunded, err := checkFunded(ctx, bal, contract, fundingID); err != nil {
} else if alreadyFunded, err := f.checkFunded(ctx, bal, contract, fundingID); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why we check the funding here before we actually do it, but this should probably be not the subject of the current PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The framework could be restarted after sending the deposit transactions, in which case we do not want to send them twice.
It is still a race condition in that case, but should mitigate most of it. This is what the docu means with It is idempotent..
@matthiasgeihs

Filter: [][]interface{}{filter},
}
}
sub, err := subscription.NewEventSub(ctx, f, contract, event, startBlockOffset)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a difference in functionality here compared to before. Before, we were starting from block 1. Here we are starting from current block - offset. I think it's OK because we also do it in other places but in general this is an open issue how to choose the startBlockOffset correctly.

Copy link
Contributor Author

@ggwpez ggwpez Jun 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will open an issue for brainstorming it.
PS: Done in #91

@matthiasgeihs matthiasgeihs merged commit e16052e into hyperledger-labs:dev Jun 2, 2021
@matthiasgeihs matthiasgeihs deleted the generic-events-sub branch June 2, 2021 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generic Event Sub
2 participants