-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add precompiles to named fork config; fix issue with maps on fork con…
…figs
- Loading branch information
1 parent
1f1aacd
commit 8497d10
Showing
5 changed files
with
119 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,43 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/params" | ||
"github.com/ethereum/go-ethereum/precompile" | ||
pcbase64 "github.com/ethereum/go-ethereum/precompile/contracts/base64" | ||
) | ||
|
||
var NullPrecompiles = precompile.PrecompileMap{} | ||
|
||
// Cache of initialized precompiles for each fork | ||
var precompileCache = make(map[string]precompile.PrecompileMap) | ||
|
||
// return precompiles that are enabled at height | ||
func PrecompileConfig(chainConfig *params.ChainConfig, height uint64, timestamp uint64) precompile.PrecompileMap { | ||
// Example, enable the base64 precompile at address 0x0000000000000000000000000000000000001000: | ||
// (add `import pcbase64 "github.com/ethereum/go-ethereum/precompile/contracts/base64"`) | ||
// return precompile.PrecompileMap{ | ||
// common.HexToAddress("0x01000"): pcbase64.NewBase64(), | ||
// } | ||
|
||
return NullPrecompiles | ||
func GetPrecompiles(chainConfig *params.ChainConfig, height uint64, timestamp uint64) precompile.PrecompileMap { | ||
fork := chainConfig.GetAstriaForks().GetForkAtHeight(height) | ||
|
||
// Return early if no precompiles configured | ||
if len(fork.Precompiles) == 0 { | ||
return NullPrecompiles | ||
} | ||
|
||
// Check if we've already initialized precompiles for this fork | ||
if cached, exists := precompileCache[fork.Name]; exists { | ||
return cached | ||
} | ||
|
||
// Initialize precompiles for this fork | ||
precompiles := make(precompile.PrecompileMap) | ||
for addr, precompileType := range fork.Precompiles { | ||
switch precompileType { | ||
case params.PrecompileBase64: | ||
precompiles[addr] = pcbase64.NewBase64() | ||
default: | ||
log.Error("Unknown precompile type", "type", precompileType, "address", addr) | ||
} | ||
} | ||
|
||
// Cache the initialized precompiles | ||
precompileCache[fork.Name] = precompiles | ||
return precompiles | ||
} |