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

feat(vald): moonbeam finality #1224

Merged
merged 3 commits into from
Jan 17, 2022
Merged

feat(vald): moonbeam finality #1224

merged 3 commits into from
Jan 17, 2022

Conversation

fish-sammy
Copy link
Contributor

@fish-sammy fish-sammy commented Jan 17, 2022

Description

Todos

  • Unit tests
  • Manual tests
  • Documentation
  • Connect epics/issues
  • Tag type of change

Steps to Test

Expected Behaviour

Other Notes

@fish-sammy fish-sammy force-pushed the feat/moonbeam-finality branch 2 times, most recently from 9675cf2 to 3a7cd67 Compare January 17, 2022 14:18
return false
}

txBlock, err := rpc.BlockByNumber(context.Background(), txReceipt.BlockNumber)
Copy link
Contributor

Choose a reason for hiding this comment

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

lines 508-523 implement step 4 from here, right? Consensus & Finality | Moonbeam Docs

As as safety check, retrieve the block by number, and verify that the given transaction hash is in the block

This is a linear search through all txs in a block. Are we sure we want to do this for all evm chains?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, even for evm chains running proof-of-work, this is beneficial in terms of safety. Linear search isn't too bad considering how many evm txs usually fit one block.

BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
Close()

ChainGetFinalizedHead(ctx context.Context) (common.Hash, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

ChainGetFinalizedHead and ChainGetHeader are moonbeam-only methods, right? May wish to add Moonbeam in the name or something to clarify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically, these chain-prefixed JSON-RPCs are already not supported by any other evm chains other than moonbeam, but I am ok with prefix it further with Moonbeam. So MoonbeamChainGetFinalizedHead and MoonbeamChainGetHeader?

_, err = client.ChainGetFinalizedHead(context.Background())
switch err := err.(type) {
case nil:
client.isMoonbeam = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be dangerous to infer moonbeam from non-nil error. Is moonbeam the only chain that will return a non-nil error here? Maybe we'll add other chains in the future that support the chain_getFinalizedHead rpc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's currently moonbeam only and these RPCs are no standard whatsoever. It's better to be GRANDPA instead of moonbeam but we are not sure if we are gonna deal with any GRANDPA chain in the future and even if we do we don't know if they are gonna implement these non-standard JSON-RPCs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there's some other chain later supports a non-standard JSON-RPC like chain_getFinalizedHead, it's highly likely they are a GRANDPA chain and the finality process remains working. In the highly unlikely case for a proof-of-work evm chain to support chain_getFinalizedHead, as long as this method still means the same thing, then we also won't have any problem with it.

@fish-sammy fish-sammy added the enhancement New feature or request label Jan 17, 2022
}

return big.NewInt(int64(blockNumber - confHeight + 1)), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

why +1 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cuz having 1 confirmation means that the tx is included in the latest block.

Comment on lines 22 to 27
BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
Close()

ChainGetFinalizedHead(ctx context.Context) (common.Hash, error)
ChainGetHeader(ctx context.Context, hash common.Hash) (*MoonbeamHeader, error)
IsMoonbeam() bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
Close()
ChainGetFinalizedHead(ctx context.Context) (common.Hash, error)
ChainGetHeader(ctx context.Context, hash common.Hash) (*MoonbeamHeader, error)
IsMoonbeam() bool
BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
Close()
type MoonbeamClient interface {
Client
ChainGetFinalizedHead(ctx context.Context) (common.Hash, error)
ChainGetHeader(ctx context.Context, hash common.Hash) (*MoonbeamHeader, error)

And instead of an isMoonbeam function, you will however have to switch on the network name that is given by the config file to know which constructor to use

Comment on lines 33 to 34
url string
isMoonbeam bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly

Suggested change
url string
isMoonbeam bool
}
type MoonbeamClientImpl struct {
ClientImpl
url string
}

@fish-sammy fish-sammy merged commit 9bdd637 into main Jan 17, 2022
@fish-sammy fish-sammy deleted the feat/moonbeam-finality branch January 17, 2022 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants