Skip to content
This repository was archived by the owner on Jun 6, 2025. It is now read-only.

Commit c5cac07

Browse files
committed
devp2p: add IP filter and ronin mainnet/testnet filter for nodeset filter
This commit adds IP or-filter, updates the ronin mainnet and testnet configuration that are used for nodeset filter. This also allows DNS sign to use password file instead of entering via prompt.
1 parent 5402fde commit c5cac07

File tree

3 files changed

+99
-9
lines changed

3 files changed

+99
-9
lines changed

cmd/devp2p/dnscmd.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"io/ioutil"
2424
"os"
2525
"path/filepath"
26+
"strings"
2627
"time"
2728

2829
"github.com/ethereum/go-ethereum/accounts/keystore"
@@ -151,10 +152,11 @@ func dnsSign(ctx *cli.Context) error {
151152
return fmt.Errorf("need tree definition directory and key file as arguments")
152153
}
153154
var (
154-
defdir = ctx.Args().Get(0)
155-
keyfile = ctx.Args().Get(1)
156-
def = loadTreeDefinition(defdir)
157-
domain = directoryName(defdir)
155+
defdir = ctx.Args().Get(0)
156+
keyfile = ctx.Args().Get(1)
157+
def = loadTreeDefinition(defdir)
158+
domain = directoryName(defdir)
159+
passwordfile string
158160
)
159161
if def.Meta.URL != "" {
160162
d, _, err := dnsdisc.ParseURL(def.Meta.URL)
@@ -176,7 +178,10 @@ func dnsSign(ctx *cli.Context) error {
176178
return err
177179
}
178180

179-
key := loadSigningKey(keyfile)
181+
if ctx.NArg() == 3 {
182+
passwordfile = ctx.Args().Get(2)
183+
}
184+
key := loadSigningKey(keyfile, passwordfile)
180185
url, err := t.Sign(key, domain)
181186
if err != nil {
182187
return fmt.Errorf("can't sign: %v", err)
@@ -252,12 +257,23 @@ func dnsNukeRoute53(ctx *cli.Context) error {
252257
}
253258

254259
// loadSigningKey loads a private key in Ethereum keystore format.
255-
func loadSigningKey(keyfile string) *ecdsa.PrivateKey {
260+
func loadSigningKey(keyfile, passwordfile string) *ecdsa.PrivateKey {
256261
keyjson, err := ioutil.ReadFile(keyfile)
257262
if err != nil {
258263
exit(fmt.Errorf("failed to read the keyfile at '%s': %v", keyfile, err))
259264
}
260-
password, _ := prompt.Stdin.PromptPassword("Please enter the password for '" + keyfile + "': ")
265+
266+
var password string
267+
if passwordfile != "" {
268+
rawPassword, err := ioutil.ReadFile(passwordfile)
269+
if err != nil {
270+
exit(fmt.Errorf("failed to read the passwordfile at '%s': %v", passwordfile, err))
271+
}
272+
password = strings.TrimRight(string(rawPassword), "\r\n")
273+
} else {
274+
password, _ = prompt.Stdin.PromptPassword("Please enter the password for '" + keyfile + "': ")
275+
}
276+
261277
key, err := keystore.DecryptKey(keyjson, password)
262278
if err != nil {
263279
exit(fmt.Errorf("error decrypting key: %v", err))

cmd/devp2p/nodesetcmd.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ type nodeFilterC struct {
136136
var filterFlags = map[string]nodeFilterC{
137137
"-limit": {1, trueFilter}, // needed to skip over -limit
138138
"-ip": {1, ipFilter},
139+
"-ip-list": {1, ipListFilter},
139140
"-min-age": {1, minAgeFilter},
140141
"-eth-network": {1, ethFilter},
141142
"-les-server": {0, lesFilter},
@@ -212,6 +213,25 @@ func ipFilter(args []string) (nodeFilter, error) {
212213
return f, nil
213214
}
214215

216+
func ipListFilter(args []string) (nodeFilter, error) {
217+
rawIpList := strings.Split(args[0], ",")
218+
var ipList []net.IP
219+
for _, rawIp := range rawIpList {
220+
ip := net.ParseIP(rawIp)
221+
ipList = append(ipList, ip)
222+
}
223+
224+
f := func(n nodeJSON) bool {
225+
for _, ip := range ipList {
226+
if ip.Equal(n.N.IP()) {
227+
return true
228+
}
229+
}
230+
return false
231+
}
232+
return f, nil
233+
}
234+
215235
func minAgeFilter(args []string) (nodeFilter, error) {
216236
minage, err := time.ParseDuration(args[0])
217237
if err != nil {
@@ -237,6 +257,10 @@ func ethFilter(args []string) (nodeFilter, error) {
237257
filter = forkid.NewStaticFilter(params.RopstenChainConfig, params.RopstenGenesisHash)
238258
case "sepolia":
239259
filter = forkid.NewStaticFilter(params.SepoliaChainConfig, params.SepoliaGenesisHash)
260+
case "ronin-mainnet":
261+
filter = forkid.NewStaticFilter(params.RoninMainnetChainConfig, params.RoninMainnetGenesisHash)
262+
case "ronin-testnet":
263+
filter = forkid.NewStaticFilter(params.RoninTestnetChainConfig, params.RoninTestnetGenesisHash)
240264
default:
241265
return nil, fmt.Errorf("unknown network %q", args[0])
242266
}

params/config.go

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var (
3434
RinkebyGenesisHash = common.HexToHash("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177")
3535
GoerliGenesisHash = common.HexToHash("0xbf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a")
3636
RoninMainnetGenesisHash = common.HexToHash("0x6e675ee97607f4e695188786c3c1853fb1562f1c075629eb5dbcff269422a1a4")
37+
RoninTestnetGenesisHash = common.HexToHash("0x13e47595099383189b8b0d5f3b67aa161495e478bb3fea64f4cf85cdf69cac4d")
3738
)
3839

3940
// TrustedCheckpoints associates each known checkpoint with the genesis hash of
@@ -235,6 +236,9 @@ var (
235236

236237
RoninMainnetBlacklistContract = common.HexToAddress("0x313b24994c93FA0471CB4D7aB796b07467041806")
237238
RoninMainnetFenixValidatorContractAddress = common.HexToAddress("0x7f13232Bdc3a010c3f749a1c25bF99f1C053CE70")
239+
RoninMainnetRoninValidatorSetAddress = common.HexToAddress("0x617c5d73662282EA7FfD231E020eCa6D2B0D552f")
240+
RoninMainnetSlashIndicatorAddress = common.HexToAddress("0xEBFFF2b32fA0dF9C5C8C5d5AAa7e8b51d5207bA3")
241+
RoninMainnetStakingContractAddress = common.HexToAddress("0x545edb750eB8769C868429BE9586F5857A768758")
238242

239243
RoninMainnetChainConfig = &ChainConfig{
240244
ChainID: big.NewInt(2020),
@@ -251,9 +255,55 @@ var (
251255
BlacklistContractAddress: &RoninMainnetBlacklistContract,
252256
FenixValidatorContractAddress: &RoninMainnetFenixValidatorContractAddress,
253257
Consortium: &ConsortiumConfig{
254-
Period: 3,
255-
Epoch: 600,
258+
Period: 3,
259+
Epoch: 600,
260+
EpochV2: 200,
256261
},
262+
ConsortiumV2Contracts: &ConsortiumV2Contracts{
263+
RoninValidatorSet: RoninMainnetRoninValidatorSetAddress,
264+
SlashIndicator: RoninMainnetSlashIndicatorAddress,
265+
StakingContract: RoninMainnetStakingContractAddress,
266+
},
267+
ConsortiumV2Block: big.NewInt(23155200),
268+
PuffyBlock: big.NewInt(0),
269+
BubaBlock: big.NewInt(0),
270+
OlekBlock: big.NewInt(24935500),
271+
}
272+
273+
RoninTestnetBlacklistContract = common.HexToAddress("0xF53EED5210c9cF308abFe66bA7CF14884c95A8aC")
274+
RoninTestnetFenixValidatorContractAddress = common.HexToAddress("0x1454cAAd1637b662432Bb795cD5773d21281eDAb")
275+
RoninTestnetRoninValidatorSetAddress = common.HexToAddress("0x54B3AC74a90E64E8dDE60671b6fE8F8DDf18eC9d")
276+
RoninTestnetSlashIndicatorAddress = common.HexToAddress("0xF7837778b6E180Df6696C8Fa986d62f8b6186752")
277+
RoninTestnetStakingContractAddress = common.HexToAddress("0x9C245671791834daf3885533D24dce516B763B28")
278+
279+
RoninTestnetChainConfig = &ChainConfig{
280+
ChainID: big.NewInt(2021),
281+
HomesteadBlock: big.NewInt(0),
282+
EIP150Block: big.NewInt(0),
283+
EIP155Block: big.NewInt(0),
284+
EIP158Block: big.NewInt(0),
285+
ByzantiumBlock: big.NewInt(0),
286+
ConstantinopleBlock: big.NewInt(0),
287+
PetersburgBlock: big.NewInt(0),
288+
IstanbulBlock: big.NewInt(0),
289+
OdysseusBlock: big.NewInt(3315095),
290+
FenixBlock: big.NewInt(6770400),
291+
BlacklistContractAddress: &RoninTestnetBlacklistContract,
292+
FenixValidatorContractAddress: &RoninTestnetFenixValidatorContractAddress,
293+
Consortium: &ConsortiumConfig{
294+
Period: 3,
295+
Epoch: 30,
296+
EpochV2: 200,
297+
},
298+
ConsortiumV2Contracts: &ConsortiumV2Contracts{
299+
RoninValidatorSet: RoninTestnetRoninValidatorSetAddress,
300+
SlashIndicator: RoninTestnetSlashIndicatorAddress,
301+
StakingContract: RoninTestnetStakingContractAddress,
302+
},
303+
ConsortiumV2Block: big.NewInt(11706000),
304+
PuffyBlock: big.NewInt(12254000),
305+
BubaBlock: big.NewInt(14260600),
306+
OlekBlock: big.NewInt(16849000),
257307
}
258308

259309
// GoerliTrustedCheckpoint contains the light client trusted checkpoint for the Görli test network.

0 commit comments

Comments
 (0)