Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
teku
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
teku
Commits
e297d217
Commit
e297d217
authored
Jul 19, 2025
by
luxq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update attacker client
parent
2ad8622f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
23 deletions
+77
-23
AttackService.java
...c/main/java/tech/pegasys/teku/attacker/AttackService.java
+6
-2
JsonRpcClientUtil.java
...in/java/tech/pegasys/teku/attacker/JsonRpcClientUtil.java
+24
-18
AttackServiceTest.java
...st/java/tech/pegasys/teku/attacker/AttackServiceTest.java
+47
-3
No files found.
attacker/client/src/main/java/tech/pegasys/teku/attacker/AttackService.java
View file @
e297d217
...
...
@@ -11,11 +11,15 @@ public class AttackService {
private
final
JsonRpcHttpClient
jsonRpcClient
;
public
AttackService
()
{
this
.
jsonRpcClient
=
JsonRpcClientUtil
.
getJsonRpcClient
();
this
.
jsonRpcClient
=
JsonRpcClientUtil
.
get
Instance
().
get
JsonRpcClient
();
}
public
AttackService
(
final
String
url
)
{
this
.
jsonRpcClient
=
JsonRpcClientUtil
.
getJsonRpcClientByUrl
(
url
);
this
.
jsonRpcClient
=
JsonRpcClientUtil
.
getInstance
().
getJsonRpcClientByUrl
(
url
);
}
public
boolean
enabled
()
{
return
this
.
jsonRpcClient
!=
null
;
}
private
SafeFuture
<
AttackerResponse
>
invokeRpc
(
final
String
method
,
final
Object
[]
params
)
{
...
...
attacker/client/src/main/java/tech/pegasys/teku/attacker/JsonRpcClientUtil.java
View file @
e297d217
...
...
@@ -7,28 +7,34 @@ import java.net.URI;
public
class
JsonRpcClientUtil
{
private
JsonRpcClientUtil
(){
private
static
final
JsonRpcClientUtil
INSTANCE
=
new
JsonRpcClientUtil
();
private
JsonRpcClientUtil
()
{
// Private constructor to prevent instantiation
}
public
static
JsonRpcHttpClient
getJsonRpcClient
(){
return
JsonRpcHttpClientSingleton
.
singleton
(
""
);
public
static
JsonRpcClientUtil
getInstance
()
{
return
INSTANCE
;
}
public
static
JsonRpcHttpClient
getJsonRpcClientByUrl
(
final
String
url
){
return
JsonRpcHttpClientSingleton
.
singleton
(
url
);
public
JsonRpcHttpClient
getJsonRpcClient
()
{
return
createJsonRpcClient
(
""
);
}
private
static
class
JsonRpcHttpClientSingleton
{
private
static
JsonRpcHttpClient
singleton
(
final
String
url
){
JsonRpcHttpClient
client
=
null
;
try
{
String
real
=
url
;
if
(
url
.
isEmpty
())
{
real
=
System
.
getenv
(
"ATTACKER_SERVICE_URL"
);
}
client
=
new
JsonRpcHttpClient
(
URI
.
create
(
real
).
toURL
());
}
catch
(
MalformedURLException
e
)
{
throw
new
RuntimeException
(
e
);
public
JsonRpcHttpClient
getJsonRpcClientByUrl
(
final
String
url
)
{
return
createJsonRpcClient
(
url
);
}
private
JsonRpcHttpClient
createJsonRpcClient
(
final
String
url
)
{
try
{
String
realUrl
=
url
.
isEmpty
()
?
System
.
getenv
(
"ATTACKER_SERVICE_URL"
)
:
url
;
if
(
realUrl
==
null
||
realUrl
.
isEmpty
())
{
return
null
;
}
else
{
return
new
JsonRpcHttpClient
(
URI
.
create
(
realUrl
).
toURL
());
}
return
client
;
}
catch
(
MalformedURLException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
}
\ No newline at end of file
attacker/client/src/test/java/tech/pegasys/teku/attacker/AttackServiceTest.java
View file @
e297d217
...
...
@@ -2,6 +2,7 @@ package tech.pegasys.teku.attacker;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
org.checkerframework.checker.units.qual.A
;
import
org.junit.jupiter.api.Test
;
import
tech.pegasys.teku.infrastructure.async.SafeFuture
;
...
...
@@ -9,16 +10,59 @@ import java.util.concurrent.ExecutionException;
public
class
AttackServiceTest
{
private
AttackService
attackService
;
@Test
public
void
attackIsNotEnabled
()
{
AttackService
s
=
new
AttackService
();
assertThat
(
s
.
enabled
()).
isEqualTo
(
false
);
}
@Test
public
void
attackIsEnabled
()
{
AttackService
s
=
new
AttackService
(
"http://127.0.0.1:12000"
);
assertThat
(
s
.
enabled
()).
isEqualTo
(
true
);
}
@Test
public
void
blockGetNewParentRoot
()
throws
ExecutionException
,
InterruptedException
{
attackService
=
new
AttackService
(
"http://127.0.0.1:12000"
);
AttackService
s
=
new
AttackService
(
"http://127.0.0.1:12000"
);
long
slot
=
1L
;
String
pub
=
""
;
String
parentRoot
=
""
;
SafeFuture
<
AttackerResponse
>
attackerResponse
=
attackService
.
blockGetNewParentRoot
(
slot
,
pub
,
parentRoot
);
SafeFuture
<
AttackerResponse
>
attackerResponse
=
s
.
blockGetNewParentRoot
(
slot
,
pub
,
parentRoot
);
assertThat
(
attackerResponse
.
get
().
getCmd
().
getValue
())
.
isEqualTo
(
AttackerCommand
.
CMD_NULL
.
getValue
());
}
public
void
blockBeforeBroadcast
()
{
AttackService
s
=
new
AttackService
(
"http://127.0.0.1:12000"
);
long
slot
=
1L
;
boolean
skipBroadCast
=
false
;
try
{
AttackerResponse
attackerResponse
=
s
.
blockBeforeBroadcast
(
slot
).
get
();
// Blocking call to get the result
switch
(
attackerResponse
.
getCmd
())
{
case
CMD_EXIT:
case
CMD_ABORT:
System
.
exit
(-
1
);
// Terminate the process
break
;
case
CMD_SKIP:
skipBroadCast
=
true
;
// Skip broadcast
break
;
case
CMD_RETURN:
// Simulate returning a response (adjust as per actual method requirements)
return
;
// Exit the method
case
CMD_NULL:
case
CMD_CONTINUE:
// Do nothing
break
;
default
:
throw
new
IllegalStateException
(
"Unexpected command received: "
+
attackerResponse
.
getCmd
());
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
"Failed to process attacker response"
,
e
);
}
System
.
out
.
println
(
"Block before broadcast completed for slot: "
+
slot
);
// then sleep 10s
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment