Skip to content

Commit

Permalink
Merge branch 'test_1_1_5' into x1-txtracing-test_1_1_5
Browse files Browse the repository at this point in the history
  • Loading branch information
nibty committed Feb 3, 2024
2 parents aed2f27 + 0c52342 commit be87945
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 23 deletions.
6 changes: 3 additions & 3 deletions cmd/opera/launcher/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ var (
Bootnodes = map[string][]string{
"main": {},
"x1-testnet": {
"enode://9ed669d0c35cc4eb7aba930d8c05b5ad8ff0e3318ad1c3c5f81ae6241b40698ef4146b2a9ac80343130df2e83f137f78648565fd810b090595c0b8b4b4123a48@34.211.87.93:5050",
"enode://c03ae9cb7a3485aba9ae3945944fad9bc678bc362bf13741033511f689df7f22063b312fac900f3fcf2ef3792e6312a84204842964085a7f0b44f4c850500405@35.155.140.94:5050",
"enode://db70d9620aeb252d18cd7309405393921da47acf2e13cd1559b190bcc5d554bf6a75c2675c2f9bb29710dcb48ae94ef9b9abe9a9baf5ab7348c35e53f3c47c8c@44.224.180.169:5050",
"enode://5d1a3b86c8ee297142fb916db77785cc679d4ed10f51cca84c9ee9442d66280a90378d9ca364620bd8cebec0aafb2cf22cd033905afe2028c22b804a2e18d981@bootnode0.x1-testnet.xen.network:5050",
"enode://703e4f01760a1f432d5e5e9a8a9c86b5dca301563bc9559f8c991de052e438d8072b2e789f7722762ea44c5c06ed87428a25606f278a128d7a39bd5996be9536@bootnode1.x1-testnet.xen.network:5050",
"enode://873de92942769e57c2360dd3198af2fda9602a9826b1f1a6d36326b6a75c9178c4f13f910c9e715a5ca6344aa62452930fcee18636ab0a95f269dded52f45960@bootnode2.x1-testnet.xen.network:5050",
},
}

Expand Down
6 changes: 5 additions & 1 deletion docker/networksimulator/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@
argparser.add_argument('--validators', type=int,
help="the number of concurrent validators to use for signing transactions")
argparser.add_argument('--rpc', type=str, default=RPC_URL, help="The RPC URL to use")
argparser.add_argument('--nonce', type=int, required=False, help="The nonce")

args = argparser.parse_args()

Expand All @@ -459,9 +460,12 @@ def run_transactions(key):
"from": acct1.address,
"to": acct1.address,
"value": Web3.to_wei(args.value, 'ether'),
'gas': args.gas
'gas': args.gas,
}

if args.nonce:
tx_params["nonce"] = args.nonce

if args.max_gas_fee and args.max_gas_priority_fee:
tx_params["maxFeePerGas"] = Web3.to_wei(args.max_gas_fee, 'gwei')
tx_params["maxPriorityFeePerGas"] = Web3.to_wei(args.max_gas_priority_fee, 'gwei')
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/ethereum/go-ethereum => github.com/faircrypto/go-ethereum v1.10.8-ftm-rc12-x1-7
replace github.com/ethereum/go-ethereum => github.com/faircrypto/go-ethereum v1.1.4-rc1-4

replace github.com/Fantom-foundation/lachesis-base => github.com/faircrypto/lachesis-base v0.0.0-20230817040848-1326ba9aa59b

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=
github.com/evalphobia/logrus_sentry v0.8.2 h1:dotxHq+YLZsT1Bb45bB5UQbfCh3gM/nFFetyN46VoDQ=
github.com/evalphobia/logrus_sentry v0.8.2/go.mod h1:pKcp+vriitUqu9KiWj/VRFbRfFNUwz95/UkgG8a6MNc=
github.com/faircrypto/go-ethereum v1.10.8-ftm-rc12-x1-7 h1:OT5kKAQ+kqmro7lnSThMHPp7kk+fOg+TCLn9K/T1ALE=
github.com/faircrypto/go-ethereum v1.10.8-ftm-rc12-x1-7/go.mod h1:ah5rnRobPJSTUKXIETbrkyrrEhWPTUPfmF1gPPNr0Tg=
github.com/faircrypto/go-ethereum v1.1.4-rc1-4 h1:1C5SKbOuwFyuMrut1SvD+qyFUlC52cA8P+TKC6igKjg=
github.com/faircrypto/go-ethereum v1.1.4-rc1-4/go.mod h1:ah5rnRobPJSTUKXIETbrkyrrEhWPTUPfmF1gPPNr0Tg=
github.com/faircrypto/lachesis-base v0.0.0-20230817040848-1326ba9aa59b h1:mEofwrV6bMlbuneVS8tnZmNZut7WY2YH++2GI7DxzHg=
github.com/faircrypto/lachesis-base v0.0.0-20230817040848-1326ba9aa59b/go.mod h1:Ogv5etzSmM2rQ4eN3OfmyitwWaaPjd4EIDiW/NAbYGk=
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8=
Expand Down
12 changes: 8 additions & 4 deletions gossip/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gossip
import (
"errors"
"fmt"
"github.com/Fantom-foundation/go-opera/version"
"math"
"math/rand"
"strings"
Expand Down Expand Up @@ -787,9 +788,12 @@ func (h *handler) handle(p *peer) error {
if !useless && (!eligibleForSnap(p.Peer) || !strings.Contains(strings.ToLower(p.Name()), "x1")) {
useless = true
discfilter.Ban(p.ID())
} else if strings.Contains(strings.ToLower(p.Name()), "1.1.3") {
log.Warn("ignore v1.1.3 peer", "peer", p.ID(), "name", p.Name())
return p2p.DiscTooManyPeers
} else {
ver := version.ParseVersionStringIntoU64(p.Peer.Name())
if ver < 1000001000005 { // version 1.1.5
log.Warn("Ignoring old peer. Sorry buddy.", "peer", p.ID(), "name", p.Name())
return p2p.DiscTooManyPeers
}
}
if !p.Peer.Info().Network.Trusted && useless {
if h.peers.UselessNum() >= h.maxPeers/10 {
Expand Down Expand Up @@ -830,7 +834,7 @@ func (h *handler) handle(p *peer) error {
p.Log().Warn("Leecher peer registration failed", "err", err)
return err
}
if p.RunningCap(ProtocolName, []uint{FTM63}) {
if p.RunningCap(ProtocolName, []uint{FTM65}) {
if err := h.epLeecher.RegisterPeer(p.id); err != nil {
p.Log().Warn("Leecher peer registration failed", "err", err)
return err
Expand Down
2 changes: 1 addition & 1 deletion gossip/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,5 +585,5 @@ func (p *snapPeer) info() *snapPeerInfo {

// eligibleForSnap checks eligibility of a peer for a snap protocol. A peer is eligible for a snap if it advertises `snap` sattelite protocol along with `opera` protocol.
func eligibleForSnap(p *p2p.Peer) bool {
return p.RunningCap(ProtocolName, []uint{FTM63}) && p.RunningCap(snap.ProtocolName, snap.ProtocolVersions)
return p.RunningCap(ProtocolName, []uint{FTM65}) && p.RunningCap(snap.ProtocolName, snap.ProtocolVersions)
}
12 changes: 6 additions & 6 deletions gossip/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ import (

// Constants to match up protocol versions and messages
const (
FTM62 = 62
FTM63 = 63
ProtocolVersion = FTM63
FTM64 = 64
FTM65 = 65
ProtocolVersion = FTM65
)

// ProtocolName is the official short name of the protocol used during capability negotiation.
const ProtocolName = "opera"
const ProtocolName = "x1"

// ProtocolVersions are the supported versions of the protocol (first is primary).
var ProtocolVersions = []uint{FTM62, FTM63}
var ProtocolVersions = []uint{FTM64, FTM65}

// protocolLengths are the number of implemented message corresponding to different protocol versions.
var protocolLengths = map[uint]uint64{FTM62: EventsStreamResponse + 1, FTM63: EPsStreamResponse + 1}
var protocolLengths = map[uint]uint64{FTM64: EventsStreamResponse + 1, FTM65: EPsStreamResponse + 1}

const protocolMaxMsgSize = inter.ProtocolMaxMsgSize // Maximum cap on the size of a protocol message

Expand Down
6 changes: 3 additions & 3 deletions system/usr/share/x1/configs/testnet/api-node.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[Node]
Testnet = true

[Node.P2P]
ListenAddr = ":5050"

# RPC server
HTTPHost = "0.0.0.0"
HTTPVirtualHosts = ["*"]
Expand Down Expand Up @@ -33,6 +30,9 @@ WSModules = [
"txpool",
]

[Node.P2P]
ListenAddr = ":5050"

[Opera]
AllowSnapsync = true

Expand Down
29 changes: 27 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package version

import (
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/params"
"math/big"
"regexp"
"strconv"
"strings"
)

func init() {
Expand Down Expand Up @@ -44,3 +46,26 @@ func ToString(major, minor, patch uint16) string {
func U64ToString(v uint64) string {
return ToString(uint16((v/1e12)%1e6), uint16((v/1e6)%1e6), uint16(v%1e6))
}

func ParseVersionString(clientName string) (major, minor, patch uint16) {
re := regexp.MustCompile(`v([0-9]+)\.([0-9]+)\.([0-9]+)`)
groups := re.FindStringSubmatch(strings.ToLower(clientName))

if len(groups) < 4 {
return 0, 0, 0
}

value, _ := strconv.ParseUint(groups[1], 10, 16)
major = uint16(value)
value, _ = strconv.ParseUint(groups[2], 10, 16)
minor = uint16(value)
value, _ = strconv.ParseUint(groups[3], 10, 16)
patch = uint16(value)

return major, minor, patch
}

func ParseVersionStringIntoU64(version string) uint64 {
major, miner, patch := ParseVersionString(version)
return ToU64(major, miner, patch)
}
60 changes: 60 additions & 0 deletions version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,63 @@ func TestAsBigInt(t *testing.T) {
prev = next
}
}

func TestParseVersion_WithValidVersion(t *testing.T) {
major, minor, patch := ParseVersionString("go-x1/v1.2.3-asdasadas")
require.Equal(t, uint16(1), major)
require.Equal(t, uint16(2), minor)
require.Equal(t, uint16(3), patch)
}

func TestParseVersion_WithInvalidVersion(t *testing.T) {
major, minor, patch := ParseVersionString("go-x1/v1.2.asdasadas")
require.Equal(t, uint16(0), major)
require.Equal(t, uint16(0), minor)
require.Equal(t, uint16(0), patch)
}

func TestParseVersion_WithNoVersion(t *testing.T) {
major, minor, patch := ParseVersionString("go-x1/asdasadas")
require.Equal(t, uint16(0), major)
require.Equal(t, uint16(0), minor)
require.Equal(t, uint16(0), patch)
}

func TestParseVersion_WithMaxUint16Version(t *testing.T) {
major, minor, patch := ParseVersionString("go-x1/v65535.65535.65535-asdasadas")
require.Equal(t, uint16(65535), major)
require.Equal(t, uint16(65535), minor)
require.Equal(t, uint16(65535), patch)
}

func TestParseVersion_WithAnotherInvalidVersion(t *testing.T) {
major, minor, patch := ParseVersionString("go-x1/v-1.2.0.asdasadas")
require.Equal(t, uint16(0), major)
require.Equal(t, uint16(0), minor)
require.Equal(t, uint16(0), patch)
}

func TestParseVersionStringIntoU64_WithValidVersion(t *testing.T) {
result := ParseVersionStringIntoU64("go-x1/v1.2.3-asdasadas")
require.Equal(t, uint64(1000002000003), result)
}

func TestParseVersionStringIntoU64_WithInvalidVersion(t *testing.T) {
result := ParseVersionStringIntoU64("go-x1/v1.2.asdasadas")
require.Equal(t, uint64(0), result)
}

func TestParseVersionStringIntoU64_WithNoVersion(t *testing.T) {
result := ParseVersionStringIntoU64("go-x1/asdasadas")
require.Equal(t, uint64(0), result)
}

func TestParseVersionStringIntoU64_WithMaxUint16Version(t *testing.T) {
result := ParseVersionStringIntoU64("go-x1/v65535.65535.65535-asdasadas")
require.Equal(t, uint64(65535065535065535), result)
}

func TestParseVersionStringIntoU64_WithMaxUint16Version2(t *testing.T) {
result := ParseVersionStringIntoU64("go-x1/v1.1.3-asdasadas")
require.Equal(t, uint64(1000001000003), result)
}

0 comments on commit be87945

Please sign in to comment.