This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
forked from 0xPolygon/polygon-edge
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EVM-607 Hard-forking PoC (0xPolygon#1544)
- Loading branch information
1 parent
7e66cd5
commit fb7a3f3
Showing
17 changed files
with
612 additions
and
141 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
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,78 @@ | ||
package forkmanager | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/0xPolygon/polygon-edge/chain" | ||
) | ||
|
||
const InitialFork = "initialfork" | ||
|
||
// HandlerDesc gives description for the handler | ||
// eq: "extra", "proposer_calculator", etc | ||
type HandlerDesc string | ||
|
||
// Fork structure defines one fork | ||
type Fork struct { | ||
// name of the fork | ||
Name string | ||
// after the fork is activated, `FromBlockNumber` shows from which block is enabled | ||
FromBlockNumber uint64 | ||
// this value is false if fork is registered but not activated | ||
IsActive bool | ||
// map of all handlers registered for this fork | ||
Handlers map[HandlerDesc]interface{} | ||
} | ||
|
||
// Handler defines one custom handler | ||
type Handler struct { | ||
// Handler should be active from block `FromBlockNumber`` | ||
FromBlockNumber uint64 | ||
// instance of some structure, function etc | ||
Handler interface{} | ||
} | ||
|
||
func ForkManagerInit(factory func(*chain.Forks) error, forks *chain.Forks) error { | ||
if factory == nil { | ||
return nil | ||
} | ||
|
||
fm := GetInstance() | ||
fm.Clear() | ||
|
||
// register initial fork | ||
fm.RegisterFork(InitialFork) | ||
|
||
// Register forks | ||
for name := range *forks { | ||
// check if fork is not supported by current edge version | ||
if _, found := (*chain.AllForksEnabled)[name]; !found { | ||
return fmt.Errorf("fork is not available: %s", name) | ||
} | ||
|
||
fm.RegisterFork(name) | ||
} | ||
|
||
// Register handlers and additional forks here | ||
if err := factory(forks); err != nil { | ||
return err | ||
} | ||
|
||
// Activate initial fork | ||
if err := fm.ActivateFork(InitialFork, uint64(0)); err != nil { | ||
return err | ||
} | ||
|
||
// Activate forks | ||
for name, blockNumber := range *forks { | ||
if blockNumber == nil { | ||
continue | ||
} | ||
|
||
if err := fm.ActivateFork(name, (uint64)(*blockNumber)); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.