forked from ethereum/go-ethereum
-
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.
- Loading branch information
Showing
62 changed files
with
6,679 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,70 @@ | ||
package utils | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"slices" | ||
"strings" | ||
|
||
"github.com/ethereum/go-ethereum/internal/flags" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/p2p" | ||
"github.com/ethereum/go-ethereum/p2p/nat" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var ( | ||
GoatNetworkFlag = &cli.StringFlag{ | ||
Name: "goat", | ||
Usage: "Run goat network", | ||
Category: flags.EthCategory, | ||
} | ||
|
||
GoatPresetFlag = &cli.StringFlag{ | ||
Name: "goat.preset", | ||
Usage: "Goat node preset", | ||
Category: flags.NetworkingCategory, | ||
} | ||
) | ||
|
||
func getPublicIP() (string, error) { | ||
resp, err := http.Get("https://checkip.amazonaws.com") | ||
if err != nil { | ||
return "", err | ||
} | ||
defer resp.Body.Close() | ||
|
||
data, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return "", err | ||
} | ||
return strings.TrimSpace(string(data)), nil | ||
} | ||
|
||
func useGoatBootnodePreset(ctx *cli.Context, cfg *p2p.Config) { | ||
if !isGoatPreset(ctx, "bootnode") { | ||
return | ||
} | ||
|
||
ip, err := getPublicIP() | ||
if err != nil { | ||
log.Error("Failed to fetch external ip", "err", err.Error()) | ||
return | ||
} | ||
log.Info("Set external public IP", "ip", ip) | ||
natif, err := nat.Parse("extip:" + ip) | ||
if err != nil { | ||
Fatalf("Failed to parse external ip", "err", err.Error()) | ||
} | ||
cfg.NAT = natif | ||
cfg.MaxPeers = 200 | ||
} | ||
|
||
func isGoatPreset(ctx *cli.Context, preset string) bool { | ||
if !ctx.IsSet(GoatPresetFlag.Name) { | ||
return false | ||
} | ||
|
||
presets := strings.Split(ctx.String(GoatPresetFlag.Name), ",") | ||
return slices.Contains(presets, preset) | ||
} |
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,53 @@ | ||
package core | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/params" | ||
"github.com/ethereum/go-ethereum/trie" | ||
) | ||
|
||
func (v *BlockValidator) validateGoatBlock(block *types.Block) error { | ||
if v.config.Goat == nil { | ||
return nil | ||
} | ||
|
||
extra := block.Header().Extra | ||
if len(extra) != params.GoatHeaderExtraLengthV0 { | ||
return fmt.Errorf("no goat tx root found (block %x)", block.Number()) | ||
} | ||
|
||
txLen, txRoot := int(extra[0]), common.BytesToHash(extra[1:]) | ||
if l := block.Transactions().Len(); l < txLen { | ||
return fmt.Errorf("txs length(%d) is less than goat tx length %d", l, txLen) | ||
} | ||
if hash := types.DeriveSha(block.Transactions()[:txLen], trie.NewStackTrie(nil)); hash != txRoot { | ||
return fmt.Errorf("goat tx root hash mismatch (header value %x, calculated %x)", txRoot, hash) | ||
} | ||
if len(block.Withdrawals()) > 0 { | ||
return errors.New("withdrawals not allowed for goat-geth") | ||
} | ||
|
||
for i, tx := range block.Transactions() { | ||
if i < txLen { | ||
if !tx.IsGoatTx() { | ||
return fmt.Errorf("transaction %d should be goat tx", i) | ||
} | ||
if tx.To() == nil { | ||
return fmt.Errorf("goat tx %d should have a to address", i) | ||
} | ||
} else { | ||
if tx.IsGoatTx() { | ||
return fmt.Errorf("transaction %d should not be goat tx", i) | ||
} | ||
if tx.Type() == types.BlobTxType { | ||
return fmt.Errorf("blob transaction %d is not allowed", i) | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.