Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master -> rskip351+rskip144 #2251

Merged
merged 49 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
651a945
Made bucketSize value configurable
Vovchyk Jan 16, 2024
6faed39
Merge branch 'master' into bucket-size-conf
Vovchyk Jan 31, 2024
5395060
Merge pull request #2228 from rsksmart/bucket-size-conf
Vovchyk Jan 31, 2024
5274b7a
- Changed Activation mock to Activation obtained by using ActivationC…
nathanieliov Jul 18, 2023
f372b2e
- Declare minimumPeginTxValue and belowMinimumPeginTxValue as class i…
nathanieliov Nov 29, 2023
90878b7
Create ErpRedeemScriptBuilders
julia-zack Nov 13, 2023
8a2e6ba
Split old LegacyErpRedeemScriptBuilder into NonStandardErp builders r…
julia-zack Nov 14, 2023
85bd468
Make ErpFederation a non-abstract class again. Inject ErpRedeemScript…
julia-zack Nov 15, 2023
5d5a6d7
Add activations argument to getOldFederation tests. Create one test f…
julia-zack Nov 16, 2023
9bf0956
Refactor bridge storage logic. Make tests related to non-standard fed…
julia-zack Nov 16, 2023
a54010b
Make saveNewFederation logic order the same as saveOldFederation
julia-zack Nov 16, 2023
eb7489b
Rename ErpRedeemScriptBuilderUtils to NonStandardErpRedeemScriptBuild…
julia-zack Nov 17, 2023
b48970e
Make erpBuilder private in federation and create an accessor method. …
julia-zack Nov 21, 2023
4b21c2d
Create getRedeemScriptParser method in ErpFederation
julia-zack Nov 23, 2023
11d2de9
Create CSV_BYTES_NEEDED_LENGTH constant
julia-zack Nov 23, 2023
91b0b9a
Make MAX_CSV_VALUE field public and use it when needed instead of def…
julia-zack Nov 23, 2023
e27f68d
Rename defineNonStandardErpRedeemScriptBuilder to getNonStandardErpRe…
julia-zack Nov 23, 2023
398cdf6
Add builders check to PowpegMigrationTest. Create getFederationDefaul…
julia-zack Nov 23, 2023
d1f5918
Modify getRedeemScriptParser method to not receive arguments. Refacto…
julia-zack Nov 24, 2023
4555c9a
Add tests for erp redeem script builder utils. Replace isSentToMulti…
julia-zack Nov 27, 2023
cd71f1b
Move builders related classes to bitcoin package and create RedeemScr…
julia-zack Nov 28, 2023
dc3eb8d
Add NonStandardErpRedeemScriptBuilderFactoryTest and ErpRedeemScriptB…
julia-zack Nov 28, 2023
e2d410e
Create FederationFactory to create federations without inconsistency …
julia-zack Dec 6, 2023
d61b240
Create federation package in tests and move federation related tests …
julia-zack Dec 7, 2023
cadc0f1
Move FederationSupport and PendingFederation outside federation packa…
julia-zack Dec 7, 2023
7a68d0b
Refactor activation of consensus rules to use ActivationConfigsForTest
julia-zack Dec 12, 2023
3148231
Move BTC_RSK_MST_PUBKEYS_COMPARATOR from FederationMember to its own …
julia-zack Dec 12, 2023
6d6711a
Move pending federation serializer behaviour to PendingFederation cla…
julia-zack Dec 21, 2023
6c0c5d6
Modify getHash test in PendingFederationTest
julia-zack Dec 22, 2023
fbe1965
Add activations to serialization logic. Adapt to that change and refa…
julia-zack Dec 22, 2023
8f9d894
Move respective deserialization methods from BridgeSerializationUtils…
julia-zack Jan 4, 2024
fd13e7b
Create FederationArgs to reduce the amount of fields the Federation c…
julia-zack Jan 3, 2024
01b4242
Create a method to build an ErpFederationArgs object from federation …
julia-zack Jan 9, 2024
eae2dd9
Rename legacy / legacy erp / erp to non standard erp due to refactors
julia-zack Jan 8, 2024
f6eeb46
Make FederationArgs fields private and create accessors. Adapt. Renam…
julia-zack Jan 10, 2024
1bce5c3
Create getErpArgs method for ErpFederation. Create tests for both Fed…
julia-zack Jan 11, 2024
ebdfe7f
Create equals methods in FederationArgs and ErpFederationArgs. Simpli…
julia-zack Jan 11, 2024
376b627
Save erpPubKeys as compressed in ErpFederation
julia-zack Jan 12, 2024
471dc02
Merge pull request #2231 from rsksmart/rebase-federations-new-refacto…
josedahlquist Jan 31, 2024
2cfd231
Used fixed buffer allocator for udp channel
Vovchyk Jan 29, 2024
0f986f2
Merge pull request #2236 from rsksmart/fixed-buf-allocator
Vovchyk Feb 5, 2024
d421333
add retry connection logic
casiojapi Dec 13, 2023
2303001
load initial boot nodes and check for closest nodes
casiojapi Dec 19, 2023
6cbf414
load max bootstrap retry limit from config
casiojapi Dec 20, 2023
1a42843
fix unit tests PeerExplorer constructor
casiojapi Dec 21, 2023
5410fe8
remove unused field
casiojapi Dec 21, 2023
b84e091
add unit tests
casiojapi Jan 8, 2024
5d5d665
improve formatting and comments
casiojapi Jan 17, 2024
5844266
Merge pull request #2213 from rsksmart/retry-connection-bootstrap-dis…
Vovchyk Feb 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions rskj-core/src/main/java/co/rsk/RskContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -1590,17 +1590,19 @@ protected PeerExplorer getPeerExplorer() {
initialBootNodes.add(address.getHostName() + ":" + address.getPort());
}
}
int bucketSize = rskSystemProperties.discoveryBucketSize();
peerExplorer = new PeerExplorer(
initialBootNodes,
localNode,
new NodeDistanceTable(KademliaOptions.BINS, KademliaOptions.BUCKET_SIZE, localNode),
new NodeDistanceTable(KademliaOptions.BINS, bucketSize, localNode),
key,
rskSystemProperties.peerDiscoveryMessageTimeOut(),
rskSystemProperties.peerDiscoveryRefreshPeriod(),
rskSystemProperties.peerDiscoveryCleanPeriod(),
rskSystemProperties.networkId(),
getPeerScoringManager(),
rskSystemProperties.allowMultipleConnectionsPerHostPort()
rskSystemProperties.allowMultipleConnectionsPerHostPort(),
rskSystemProperties.peerDiscoveryMaxBootRetries()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import co.rsk.bitcoinj.core.Coin;
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.peg.AddressBasedAuthorizer;
import co.rsk.peg.Federation;
import co.rsk.peg.federation.Federation;
import java.util.List;

import org.ethereum.config.blockchain.upgrades.ActivationConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import co.rsk.bitcoinj.core.Coin;
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.peg.AddressBasedAuthorizer;
import co.rsk.peg.FederationMember;
import co.rsk.peg.StandardMultisigFederation;
import co.rsk.peg.federation.FederationArgs;
import co.rsk.peg.federation.FederationMember;
import co.rsk.peg.federation.FederationFactory;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -57,12 +58,8 @@ public BridgeDevNetConstants(List<BtcECKey> federationPublicKeys) {

// Expected federation address is:
// 2NCEo1RdmGDj6MqiipD6DUSerSxKv79FNWX
genesisFederation = new StandardMultisigFederation(
federationMembers,
genesisFederationAddressCreatedAt,
1L,
getBtcParams()
);
FederationArgs federationArgs = new FederationArgs(federationMembers, genesisFederationAddressCreatedAt, 1L, getBtcParams());
genesisFederation = FederationFactory.buildStandardMultiSigFederation(federationArgs);

btc2RskMinimumAcceptableConfirmations = 1;
btc2RskMinimumAcceptableConfirmationsOnRsk = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import co.rsk.bitcoinj.core.Coin;
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.peg.AddressBasedAuthorizer;
import co.rsk.peg.FederationMember;
import co.rsk.peg.StandardMultisigFederation;
import co.rsk.peg.federation.FederationArgs;
import co.rsk.peg.federation.FederationMember;
import co.rsk.peg.federation.FederationFactory;
import com.google.common.collect.Lists;
import java.time.Instant;
import java.util.Arrays;
Expand Down Expand Up @@ -52,12 +53,8 @@ public class BridgeMainNetConstants extends BridgeConstants {
// Wednesday, January 3, 2018 12:00:00 AM GMT-03:00
Instant genesisFederationAddressCreatedAt = Instant.ofEpochMilli(1514948400L);

genesisFederation = new StandardMultisigFederation(
federationMembers,
genesisFederationAddressCreatedAt,
1L,
getBtcParams()
);
FederationArgs federationArgs = new FederationArgs(federationMembers, genesisFederationAddressCreatedAt, 1L, getBtcParams());
genesisFederation = FederationFactory.buildStandardMultiSigFederation(federationArgs);

btc2RskMinimumAcceptableConfirmations = 100;
btc2RskMinimumAcceptableConfirmationsOnRsk = 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import co.rsk.bitcoinj.core.Coin;
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.peg.AddressBasedAuthorizer;
import co.rsk.peg.FederationMember;
import co.rsk.peg.StandardMultisigFederation;
import co.rsk.peg.federation.FederationArgs;
import co.rsk.peg.federation.FederationMember;
import co.rsk.peg.federation.FederationFactory;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.ZonedDateTime;
Expand Down Expand Up @@ -55,12 +56,8 @@ public BridgeRegTestConstants(List<BtcECKey> federationPublicKeys) {

Instant genesisFederationCreatedAt = ZonedDateTime.parse("2016-01-01T00:00:00Z").toInstant();

genesisFederation = new StandardMultisigFederation(
federationMembers,
genesisFederationCreatedAt,
1L,
getBtcParams()
);
FederationArgs federationArgs = new FederationArgs(federationMembers, genesisFederationCreatedAt, 1L, getBtcParams());
genesisFederation = FederationFactory.buildStandardMultiSigFederation(federationArgs);

btc2RskMinimumAcceptableConfirmations = 3;
btc2RskMinimumAcceptableConfirmationsOnRsk = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import co.rsk.bitcoinj.core.Coin;
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.peg.AddressBasedAuthorizer;
import co.rsk.peg.FederationMember;
import co.rsk.peg.StandardMultisigFederation;
import co.rsk.peg.federation.FederationArgs;
import co.rsk.peg.federation.FederationMember;
import co.rsk.peg.federation.FederationFactory;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -65,12 +66,8 @@ public class BridgeTestNetConstants extends BridgeConstants {
// Currently set to: Monday, October 8, 2018 12:00:00 AM GMT-03:00
Instant genesisFederationAddressCreatedAt = Instant.ofEpochMilli(1538967600l);

genesisFederation = new StandardMultisigFederation(
federationMembers,
genesisFederationAddressCreatedAt,
1L,
getBtcParams()
);
FederationArgs federationArgs = new FederationArgs(federationMembers, genesisFederationAddressCreatedAt, 1L, getBtcParams());
genesisFederation = FederationFactory.buildStandardMultiSigFederation(federationArgs);

btc2RskMinimumAcceptableConfirmations = 10;
btc2RskMinimumAcceptableConfirmationsOnRsk = 10;
Expand Down
13 changes: 13 additions & 0 deletions rskj-core/src/main/java/co/rsk/config/RskSystemProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package co.rsk.config;

import co.rsk.core.RskAddress;
import co.rsk.net.discovery.table.KademliaOptions;
import co.rsk.rpc.ModuleDescription;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigObject;
Expand Down Expand Up @@ -46,6 +47,9 @@ public class RskSystemProperties extends SystemProperties {
private static final int PD_DEFAULT_CLEAN_PERIOD = 15000; //miliseconds
private static final int PD_DEFAULT_TIMEOUT_MESSAGE = PD_DEFAULT_CLEAN_PERIOD - 1; //miliseconds
private static final int PD_DEFAULT_REFRESH_PERIOD = 60000; //miliseconds
private static final int PD_DEFAULT_MAX_BOOTSTRAP_RETRIES = -1;

private static final String PD_MAX_BOOTSTRAP_RETRIES_CONFIG = "peer.discovery.maxBootRetries";

private static final String REGTEST_BLOCKCHAIN_CONFIG = "regtest";

Expand All @@ -55,6 +59,7 @@ public class RskSystemProperties extends SystemProperties {
private static final String RPC_ETH_GET_LOGS_MAX_BLOCKS_TO_QUERY = "rpc.logs.maxBlocksToQuery";
private static final String RPC_ETH_GET_LOGS_MAX_LOGS_TO_RETURN = "rpc.logs.maxLogsToReturn";
private static final String RPC_GAS_PRICE_MULTIPLIER_CONFIG = "rpc.gasPriceMultiplier";
private static final String DISCOVERY_BUCKET_SIZE = "peer.discovery.bucketSize";

private static final int CHUNK_SIZE = 192;

Expand Down Expand Up @@ -260,6 +265,14 @@ public boolean allowMultipleConnectionsPerHostPort() {
return getBoolean("peer.discovery.allowMultipleConnectionsPerHostPort", true);
}

public long peerDiscoveryMaxBootRetries() {
return getLong(PD_MAX_BOOTSTRAP_RETRIES_CONFIG, PD_DEFAULT_MAX_BOOTSTRAP_RETRIES);
}

public int discoveryBucketSize() {
return getInt(DISCOVERY_BUCKET_SIZE, KademliaOptions.BUCKET_SIZE);
}

public List<ModuleDescription> getRpcModules() {
if (this.moduleDescriptions != null) {
return this.moduleDescriptions;
Expand Down
41 changes: 31 additions & 10 deletions rskj-core/src/main/java/co/rsk/net/discovery/PeerExplorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
Expand All @@ -63,6 +58,9 @@ public class PeerExplorer {
private static final int MAX_NODES_TO_CHECK = 16;
private static final int RETRIES_COUNT = 3;

private final List<String> initialBootNodes;
private int retryCounter = 0;
private final long maxBootRetries;
private final Set<InetSocketAddress> bootNodes = ConcurrentHashMap.newKeySet();

private final Map<String, PeerDiscoveryRequest> pendingPingRequests = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -98,12 +96,13 @@ public class PeerExplorer {
public PeerExplorer(List<String> initialBootNodes,
Node localNode, NodeDistanceTable distanceTable, ECKey key,
long reqTimeOut, long updatePeriod, long cleanPeriod, Integer networkId,
PeerScoringManager peerScoringManager, boolean allowMultipleConnectionsPerHostPort) {
PeerScoringManager peerScoringManager, boolean allowMultipleConnectionsPerHostPort, long maxBootRetries) {
this.localNode = localNode;
this.key = key;
this.distanceTable = distanceTable;
this.updateEntryLock = new ReentrantLock();
this.networkId = networkId;
this.initialBootNodes = Collections.unmodifiableList(new ArrayList<>(initialBootNodes));
loadInitialBootNodes(initialBootNodes);

this.cleaner = new PeerExplorerCleaner(updatePeriod, cleanPeriod, this);
Expand All @@ -114,6 +113,8 @@ public PeerExplorer(List<String> initialBootNodes,

this.knownHosts = new ConcurrentHashMap<>();
this.allowMultipleConnectionsPerHostPort = allowMultipleConnectionsPerHostPort;

this.maxBootRetries = maxBootRetries;
}

void start() {
Expand Down Expand Up @@ -149,6 +150,11 @@ ExecState getState() {
return state;
}

@VisibleForTesting
int getRetryCounter() {
return retryCounter;
}

@VisibleForTesting
Set<String> startConversationWithNewNodes() {
Set<String> sentAddresses = new HashSet<>();
Expand Down Expand Up @@ -429,10 +435,25 @@ synchronized void update() {

List<Node> closestNodes = this.distanceTable.getClosestNodes(this.localNode.getId());

logger.trace("update - closestNodes: [{}]", closestNodes);
if (shouldRetryConnection(closestNodes)) {
if (maxBootRetries == -1 || retryCounter < maxBootRetries) {
retryCounter++;
logger.info("retrying connection to bootstrap nodes. Attempt: {}", retryCounter);
loadInitialBootNodes(initialBootNodes);
startConversationWithNewNodes();
} else {
logger.warn("max retry attempts reached.");
}
} else {
logger.trace("update - closestNodes: [{}]", closestNodes);
this.askForMoreNodes(closestNodes);
this.checkPeersPulse(closestNodes);
}
}

this.askForMoreNodes(closestNodes);
this.checkPeersPulse(closestNodes);
private boolean shouldRetryConnection(List<Node> closestNodes) {
return closestNodes.isEmpty() && bootNodes.isEmpty() && pendingPingRequests.isEmpty() &&
pendingFindNodeRequests.isEmpty() && establishedConnections.isEmpty();
}

private void checkPeersPulse(List<Node> closestNodes) {
Expand Down
30 changes: 27 additions & 3 deletions rskj-core/src/main/java/co/rsk/net/discovery/UDPServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
import co.rsk.util.ExecState;
import com.google.common.annotations.VisibleForTesting;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.DatagramChannelConfig;
import io.netty.channel.socket.nio.NioDatagramChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -43,6 +42,8 @@ public class UDPServer implements InternalService {

private static final Logger logger = LoggerFactory.getLogger(UDPServer.class);

private static final int BUFFER_SIZE = 8_192;

private final int port;
private final String address;

Expand Down Expand Up @@ -163,6 +164,29 @@ private Bootstrap createBootstrap(EventLoopGroup group) {
.handler(new ChannelInitializer<NioDatagramChannel>() {
@Override
public void initChannel(@Nonnull NioDatagramChannel ch) {
DatagramChannelConfig channelConfig = ch.config();
channelConfig.setRecvByteBufAllocator(new FixedRecvByteBufAllocator(BUFFER_SIZE));

Integer defaultSndBuf = channelConfig.getOption(ChannelOption.SO_SNDBUF);
if (defaultSndBuf == null || defaultSndBuf < BUFFER_SIZE) {
logger.info("Default {} size of {} bytes is not sufficient. Changing to {}",
ChannelOption.SO_SNDBUF, defaultSndBuf, BUFFER_SIZE);
channelConfig.setOption(ChannelOption.SO_SNDBUF, BUFFER_SIZE);
}

Integer defaultRcvBuf = channelConfig.getOption(ChannelOption.SO_RCVBUF);
if (defaultRcvBuf == null || defaultRcvBuf < BUFFER_SIZE) {
logger.info("Default {} size of {} bytes is not sufficient. Changing to {}",
ChannelOption.SO_RCVBUF, defaultRcvBuf, BUFFER_SIZE);
channelConfig.setOption(ChannelOption.SO_RCVBUF, BUFFER_SIZE);
}

logger.info("Init channel with {}({}), {}={}, {}={}",
FixedRecvByteBufAllocator.class.getSimpleName(),
BUFFER_SIZE,
ChannelOption.SO_SNDBUF, channelConfig.getOption(ChannelOption.SO_SNDBUF),
ChannelOption.SO_RCVBUF, channelConfig.getOption(ChannelOption.SO_RCVBUF));

ch.pipeline().addLast(new PacketDecoder());
UDPChannel udpChannel = new UDPChannel(ch, peerExplorer);
peerExplorer.setUDPChannel(udpChannel);
Expand Down
2 changes: 2 additions & 0 deletions rskj-core/src/main/java/co/rsk/peg/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import co.rsk.crypto.Keccak256;
import co.rsk.panic.PanicProcessor;
import co.rsk.peg.bitcoin.MerkleBranch;
import co.rsk.peg.federation.Federation;
import co.rsk.peg.federation.FederationMember;
import co.rsk.peg.flyover.FlyoverTxResponseCodes;
import co.rsk.peg.utils.BtcTransactionFormatUtils;
import co.rsk.peg.whitelist.LockWhitelistEntry;
Expand Down
1 change: 1 addition & 0 deletions rskj-core/src/main/java/co/rsk/peg/BridgeBtcWallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import co.rsk.bitcoinj.core.Context;
import co.rsk.bitcoinj.wallet.RedeemData;
import co.rsk.bitcoinj.wallet.Wallet;
import co.rsk.peg.federation.Federation;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
Expand Down
Loading
Loading