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

EVM-607 Hard-forking PoC #1544

Merged
merged 16 commits into from
Jun 2, 2023
Merged

EVM-607 Hard-forking PoC #1544

merged 16 commits into from
Jun 2, 2023

Conversation

igorcrevar
Copy link
Contributor

@igorcrevar igorcrevar commented May 24, 2023

Description

Forking Manager PoC

Example:
Let's say we have three forks: A, B, and C, with starting blocks 0, 10, and 20, respectively. For each fork, we have a simple handler that returns a string. We can achieve this using the code example below

fm := GetInstance()

const handlerDesc = "fn"

type handlerFn func() string

// define handlers
var (
    h1 handlerFn = func() string { return "Handler for fork A" }
    h2 handlerFn = func() string { return "Handler for fork B" }
    h3 handlerFn = func() string { return "Handler for fork C" }
)

// register forks
fm.RegisterFork("A")
fm.RegisterFork("B")
fm.RegisterFork("C")

// register handlers
assert.NoError(t, fm.RegisterHandler("A", handlerDesc, h1))
assert.NoError(t, fm.RegisterHandler("B", handlerDesc, h2))
assert.NoError(t, fm.RegisterHandler("C", handlerDesc, h3))

// activate forks
assert.NoError(t, fm.ActivateFork("A", 0))
assert.NoError(t, fm.ActivateFork("B", 10))
assert.NoError(t, fm.ActivateFork("C", 20))

// check if appropriate handler is called for some block number
for i := 0; i < 50; i++ {
    handler := fm.GetHandler(handlerDesc, uint64(i)).(handlerFn)
    
    if i < 10 {
	 assert.Equal(t, "Handler for fork A", handler())
    } else if i < 20 {
	 assert.Equal(t, "Handler for fork B", handler())
    } else {
	 assert.Equal(t, "Handler for fork C", handler())
    }
}

Changes include

  • Bugfix (non-breaking change that solves an issue)
  • Hotfix (change that solves an urgent issue, and requires immediate attention)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)

Breaking changes

Please complete this section if any breaking changes have been made, otherwise delete it

Checklist

  • I have assigned this PR to myself
  • I have added at least 1 reviewer
  • I have added the relevant labels
  • I have updated the official documentation
  • I have added sufficient documentation in code

Testing

  • I have tested this code with the official test suite
  • I have tested this code manually

Manual tests

Please complete this section if you ran manual tests for this functionality, otherwise delete it

Documentation update

Please link the documentation update PR in this section if it's present, otherwise delete it

Additional comments

Please post additional comments in this section if you have them, otherwise delete it

@igorcrevar igorcrevar force-pushed the feature/forking_poc branch 4 times, most recently from 8f9a6ac to 647bd04 Compare May 25, 2023 11:14
@igorcrevar igorcrevar self-assigned this May 25, 2023
@igorcrevar igorcrevar added the feature New update to Polygon Edge label May 25, 2023
@igorcrevar igorcrevar changed the title Forking Manager PoC EVM-607 Hard-forking PoC May 25, 2023
@igorcrevar igorcrevar force-pushed the feature/forking_poc branch 5 times, most recently from a4e4e35 to aa4dfb9 Compare May 26, 2023 11:22
@Nemanja0x Nemanja0x marked this pull request as ready for review May 27, 2023 15:03
forkmanager/fork.go Outdated Show resolved Hide resolved
consensus/polybft/polybft.go Outdated Show resolved Hide resolved
consensus/polybft/polybft.go Outdated Show resolved Hide resolved
tests/testing.go Outdated Show resolved Hide resolved
@igorcrevar igorcrevar force-pushed the feature/forking_poc branch 2 times, most recently from 79e7065 to f9398e1 Compare May 29, 2023 10:37
@igorcrevar igorcrevar force-pushed the feature/forking_poc branch 7 times, most recently from 39293a0 to b85bf23 Compare May 29, 2023 12:41
forkmanager/fork.go Outdated Show resolved Hide resolved
consensus/polybft/polybft.go Outdated Show resolved Hide resolved
forkmanager/fork_manager.go Outdated Show resolved Hide resolved
forkmanager/fork_manager.go Outdated Show resolved Hide resolved
forkmanager/fork_manager.go Outdated Show resolved Hide resolved
forkmanager/fork_manager.go Outdated Show resolved Hide resolved
Copy link
Contributor

@vcastellm vcastellm left a comment

Choose a reason for hiding this comment

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

Can you add a small code example on how a handler should be used?

Copy link
Contributor

@vcastellm vcastellm left a comment

Choose a reason for hiding this comment

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

Can you add a small code example on how a handler should be used in the PR body?

@igorcrevar
Copy link
Contributor Author

Example is here #1567

Copy link
Contributor

@goran-ethernal goran-ethernal left a comment

Choose a reason for hiding this comment

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

Copy link
Contributor

@vcastellm vcastellm left a comment

Choose a reason for hiding this comment

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

LGTM

@igorcrevar igorcrevar merged commit fb7a3f3 into develop Jun 2, 2023
5 of 6 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New update to Polygon Edge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants