Skip to content

Commit

Permalink
1545 Second pull request fix ddos test
Browse files Browse the repository at this point in the history
  • Loading branch information
kladkogex committed Feb 19, 2025
1 parent 3ed3a20 commit 62c0372
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
10 changes: 6 additions & 4 deletions libethereum/SkaleHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,6 @@ void SkaleHost::stopWorking() {
m_exitNeeded = true;
pauseConsensus( false );

cnote << "1 before exitGracefully()";

if ( ExitHandler::shouldExit() ) {
// requested exit
Expand All @@ -745,16 +744,19 @@ void SkaleHost::stopWorking() {
clog( VerbosityInfo, "skale-host" ) << cc::info( "Exiting without request" );
}


cnote << "Skaled initiating consensus graceful exit";

m_consensus->exitGracefully();

cnote << "2 after exitGracefully()";
cnote << "Exit initiated. Skaled waiting for consensus exit.";

while ( m_consensus->getStatus() != CONSENSUS_EXITED ) {
timespec ms100{ 0, 100000000 };
nanosleep( &ms100, nullptr );
}

cnote << "3 after wait loop";
cnote << "Consensus status is exited. Skaled is waiting for consensus and broadcast to finish.";

if ( m_consensusThread.joinable() )
m_consensusThread.join();
Expand All @@ -764,7 +766,7 @@ void SkaleHost::stopWorking() {

working = false;

cnote << "4 before dtor";
cnote << "Consensus and broadcat threads finished.";
}

void SkaleHost::broadcastFunc() {
Expand Down
43 changes: 32 additions & 11 deletions test/unittests/libweb3jsonrpc/run_skaled.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,29 @@ def wait_until_online(self, _timeoutSec: int) :
for i in range(_timeoutSec):
if self.check_if_online():
return
print("Waiting for instance to be online Instance is not online.", flush= True)
time.sleep(1)
print(f"Timeout reached. Node {self.index} did not get online.", flush= True)
test_print(f"Timeout reached. Node {self.index} did not get online.")
assert False

def wait_until_exit(self, _timeoutSec: int) :
for i in range(_timeoutSec):
if not self.is_running():
return
time.sleep(1)
test_print(f"Timeout reached. Node {self.index} did not exit.")



def wait_for_exit(self) :
self.process.wait()

def graceful_exit(self):
if self.process.poll() is None:
if self.is_running():
self.process.terminate()


def is_running(self) -> bool:
return self.process.poll() is None
def kill(self):
if self.process.poll() is None:
if self.is_running():
self.process.terminate()


Expand All @@ -80,7 +87,6 @@ def get_listening_ports_by_pid(pid: int):
for conn in psutil.net_connections(kind='inet')
if conn.status == psutil.CONN_LISTEN and conn.pid == pid
)
print(listening_ports, flush = True)
return listening_ports

def read_stdout(pipe):
Expand All @@ -92,7 +98,6 @@ def read_stdout(pipe):

def run_skaled(_schain_index: int, _total_nodes: int):
try:
print("Starting skaled...")
skaled_dir : str = f"/tmp/skaled_{_schain_index}_of_{_total_nodes}"
skaled_path = Path(skaled_dir)

Expand All @@ -116,25 +121,41 @@ def run_skaled(_schain_index: int, _total_nodes: int):
Skaled.stdout_thread.start()

except Exception as e:
print(f"Exception occurred: {e}")
print(f"Node {self.index} Exception occurred: {e}")


def test_print(_s: str):
print(f"TEST_SCRIPT:{_s}", flush = True)

def main():



print("TEST SCRIPT: Starting all nodes ")

for i in range(TOTAL_NODES):
run_skaled(i + 1, TOTAL_NODES)


print("TEST SCRIPT: Waiting until all nodes in the chain are online ")
test_print("Waiting nodes are online ")
for i in range(TOTAL_NODES):
skaled : Skaled = skaleds[i]
skaled.wait_until_online(20)
print("TEST SCRIPT: All nodes are online ...")
test_print("All nodes online")


test_print("Sending graceful signal to all nodes")
for i in range(TOTAL_NODES):
skaled : Skaled = skaleds[i]
skaled.graceful_exit()

test_print("Sending graceful signal to all nodes")
for i in range(TOTAL_NODES):
skaled : Skaled = skaleds[i]
skaled.wait_until_exit(50)


test_print("Exited. Waiting for processes to stop.")
for i in range(TOTAL_NODES):
skaled : Skaled = skaleds[i]
skaled.process.wait()
Expand Down

0 comments on commit 62c0372

Please sign in to comment.