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
2ad8622f
Commit
2ad8622f
authored
Jul 18, 2025
by
luxq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix error
parent
576d9934
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
27 deletions
+46
-27
AttackService.java
...c/main/java/tech/pegasys/teku/attacker/AttackService.java
+19
-15
AttackerCommand.java
...main/java/tech/pegasys/teku/attacker/AttackerCommand.java
+2
-2
AttackerResponse.java
...ain/java/tech/pegasys/teku/attacker/AttackerResponse.java
+1
-1
JsonRpcClientUtil.java
...in/java/tech/pegasys/teku/attacker/JsonRpcClientUtil.java
+13
-5
AttackServiceTest.java
...st/java/tech/pegasys/teku/attacker/AttackServiceTest.java
+11
-4
No files found.
attacker/client/src/main/java/tech/pegasys/teku/attacker/AttackService.java
View file @
2ad8622f
...
@@ -14,7 +14,11 @@ public class AttackService {
...
@@ -14,7 +14,11 @@ public class AttackService {
this
.
jsonRpcClient
=
JsonRpcClientUtil
.
getJsonRpcClient
();
this
.
jsonRpcClient
=
JsonRpcClientUtil
.
getJsonRpcClient
();
}
}
private
SafeFuture
<
AttackerResponse
>
invokeRpc
(
String
method
,
Object
[]
params
)
{
public
AttackService
(
final
String
url
)
{
this
.
jsonRpcClient
=
JsonRpcClientUtil
.
getJsonRpcClientByUrl
(
url
);
}
private
SafeFuture
<
AttackerResponse
>
invokeRpc
(
final
String
method
,
final
Object
[]
params
)
{
try
{
try
{
AttackerResponse
response
=
jsonRpcClient
.
invoke
(
method
,
params
,
AttackerResponse
.
class
);
AttackerResponse
response
=
jsonRpcClient
.
invoke
(
method
,
params
,
AttackerResponse
.
class
);
return
SafeFuture
.
completedFuture
(
response
);
return
SafeFuture
.
completedFuture
(
response
);
...
@@ -25,59 +29,59 @@ public class AttackService {
...
@@ -25,59 +29,59 @@ public class AttackService {
}
}
}
}
public
SafeFuture
<
AttackerResponse
>
blockGetNewParentRoot
(
long
slot
,
String
pubkey
,
String
parentRoot
)
{
public
SafeFuture
<
AttackerResponse
>
blockGetNewParentRoot
(
final
long
slot
,
final
String
pubkey
,
final
String
parentRoot
)
{
return
invokeRpc
(
BLOCK_MODULE
+
"_getNewParentRoot"
,
new
Object
[]{
slot
,
pubkey
,
parentRoot
});
return
invokeRpc
(
BLOCK_MODULE
+
"_getNewParentRoot"
,
new
Object
[]{
slot
,
pubkey
,
parentRoot
});
}
}
public
SafeFuture
<
AttackerResponse
>
delayForReceiveBlock
(
long
slot
)
{
public
SafeFuture
<
AttackerResponse
>
delayForReceiveBlock
(
final
long
slot
)
{
return
invokeRpc
(
BLOCK_MODULE
+
"_delayForReceiveBlock"
,
new
Object
[]{
slot
});
return
invokeRpc
(
BLOCK_MODULE
+
"_delayForReceiveBlock"
,
new
Object
[]{
slot
});
}
}
public
SafeFuture
<
AttackerResponse
>
blockBeforeBroadcast
(
long
slot
)
{
public
SafeFuture
<
AttackerResponse
>
blockBeforeBroadcast
(
final
long
slot
)
{
return
invokeRpc
(
BLOCK_MODULE
+
"_beforeBroadCast"
,
new
Object
[]{
slot
});
return
invokeRpc
(
BLOCK_MODULE
+
"_beforeBroadCast"
,
new
Object
[]{
slot
});
}
}
public
SafeFuture
<
AttackerResponse
>
blockAfterBroadcast
(
long
slot
)
{
public
SafeFuture
<
AttackerResponse
>
blockAfterBroadcast
(
final
long
slot
)
{
return
invokeRpc
(
BLOCK_MODULE
+
"_afterBroadCast"
,
new
Object
[]{
slot
});
return
invokeRpc
(
BLOCK_MODULE
+
"_afterBroadCast"
,
new
Object
[]{
slot
});
}
}
public
SafeFuture
<
AttackerResponse
>
blockBeforeSign
(
long
slot
,
String
pubkey
,
String
blockDataBase64
)
{
public
SafeFuture
<
AttackerResponse
>
blockBeforeSign
(
final
long
slot
,
final
String
pubkey
,
final
String
blockDataBase64
)
{
return
invokeRpc
(
BLOCK_MODULE
+
"_beforeSign"
,
new
Object
[]{
slot
,
pubkey
,
blockDataBase64
});
return
invokeRpc
(
BLOCK_MODULE
+
"_beforeSign"
,
new
Object
[]{
slot
,
pubkey
,
blockDataBase64
});
}
}
public
SafeFuture
<
AttackerResponse
>
blockAfterSign
(
long
slot
,
String
pubkey
,
String
signedBlockDataBase64
)
{
public
SafeFuture
<
AttackerResponse
>
blockAfterSign
(
final
long
slot
,
final
String
pubkey
,
final
String
signedBlockDataBase64
)
{
return
invokeRpc
(
BLOCK_MODULE
+
"_afterSign"
,
new
Object
[]{
slot
,
pubkey
,
signedBlockDataBase64
});
return
invokeRpc
(
BLOCK_MODULE
+
"_afterSign"
,
new
Object
[]{
slot
,
pubkey
,
signedBlockDataBase64
});
}
}
public
SafeFuture
<
AttackerResponse
>
blockBeforePropose
(
long
slot
,
String
pubkey
,
String
signedBlockDataBase64
)
{
public
SafeFuture
<
AttackerResponse
>
blockBeforePropose
(
final
long
slot
,
final
String
pubkey
,
final
String
signedBlockDataBase64
)
{
return
invokeRpc
(
BLOCK_MODULE
+
"_beforePropose"
,
new
Object
[]{
slot
,
pubkey
,
signedBlockDataBase64
});
return
invokeRpc
(
BLOCK_MODULE
+
"_beforePropose"
,
new
Object
[]{
slot
,
pubkey
,
signedBlockDataBase64
});
}
}
public
SafeFuture
<
AttackerResponse
>
blockAfterPropose
(
long
slot
,
String
pubkey
,
String
signedBlockDataBase64
)
{
public
SafeFuture
<
AttackerResponse
>
blockAfterPropose
(
final
long
slot
,
final
String
pubkey
,
final
String
signedBlockDataBase64
)
{
return
invokeRpc
(
BLOCK_MODULE
+
"_afterPropose"
,
new
Object
[]{
slot
,
pubkey
,
signedBlockDataBase64
});
return
invokeRpc
(
BLOCK_MODULE
+
"_afterPropose"
,
new
Object
[]{
slot
,
pubkey
,
signedBlockDataBase64
});
}
}
public
SafeFuture
<
AttackerResponse
>
attestBeforeBroadcast
(
long
slot
)
{
public
SafeFuture
<
AttackerResponse
>
attestBeforeBroadcast
(
final
long
slot
)
{
return
invokeRpc
(
ATTEST_MODULE
+
"_beforeBroadCast"
,
new
Object
[]{
slot
});
return
invokeRpc
(
ATTEST_MODULE
+
"_beforeBroadCast"
,
new
Object
[]{
slot
});
}
}
public
SafeFuture
<
AttackerResponse
>
attestAfterBroadcast
(
long
slot
)
{
public
SafeFuture
<
AttackerResponse
>
attestAfterBroadcast
(
final
long
slot
)
{
return
invokeRpc
(
ATTEST_MODULE
+
"_afterBroadCast"
,
new
Object
[]{
slot
});
return
invokeRpc
(
ATTEST_MODULE
+
"_afterBroadCast"
,
new
Object
[]{
slot
});
}
}
public
SafeFuture
<
AttackerResponse
>
attestBeforeSign
(
long
slot
,
String
pubkey
,
String
attestDataBase64
)
{
public
SafeFuture
<
AttackerResponse
>
attestBeforeSign
(
final
long
slot
,
final
String
pubkey
,
final
String
attestDataBase64
)
{
return
invokeRpc
(
ATTEST_MODULE
+
"_beforeSign"
,
new
Object
[]{
slot
,
pubkey
,
attestDataBase64
});
return
invokeRpc
(
ATTEST_MODULE
+
"_beforeSign"
,
new
Object
[]{
slot
,
pubkey
,
attestDataBase64
});
}
}
public
SafeFuture
<
AttackerResponse
>
attestAfterSign
(
long
slot
,
String
pubkey
,
String
signedAttestDataBase64
)
{
public
SafeFuture
<
AttackerResponse
>
attestAfterSign
(
final
long
slot
,
final
String
pubkey
,
final
String
signedAttestDataBase64
)
{
return
invokeRpc
(
ATTEST_MODULE
+
"_afterSign"
,
new
Object
[]{
slot
,
pubkey
,
signedAttestDataBase64
});
return
invokeRpc
(
ATTEST_MODULE
+
"_afterSign"
,
new
Object
[]{
slot
,
pubkey
,
signedAttestDataBase64
});
}
}
public
SafeFuture
<
AttackerResponse
>
attestBeforePropose
(
long
slot
,
String
pubkey
,
String
signedAttestDataBase64
)
{
public
SafeFuture
<
AttackerResponse
>
attestBeforePropose
(
final
long
slot
,
final
String
pubkey
,
final
String
signedAttestDataBase64
)
{
return
invokeRpc
(
ATTEST_MODULE
+
"_beforePropose"
,
new
Object
[]{
slot
,
pubkey
,
signedAttestDataBase64
});
return
invokeRpc
(
ATTEST_MODULE
+
"_beforePropose"
,
new
Object
[]{
slot
,
pubkey
,
signedAttestDataBase64
});
}
}
public
SafeFuture
<
AttackerResponse
>
attestAfterPropose
(
long
slot
,
String
pubkey
,
String
signedAttestDataBase64
)
{
public
SafeFuture
<
AttackerResponse
>
attestAfterPropose
(
final
long
slot
,
final
String
pubkey
,
final
String
signedAttestDataBase64
)
{
return
invokeRpc
(
ATTEST_MODULE
+
"_afterPropose"
,
new
Object
[]{
slot
,
pubkey
,
signedAttestDataBase64
});
return
invokeRpc
(
ATTEST_MODULE
+
"_afterPropose"
,
new
Object
[]{
slot
,
pubkey
,
signedAttestDataBase64
});
}
}
}
}
\ No newline at end of file
attacker/client/src/main/java/tech/pegasys/teku/attacker/AttackerCommand.java
View file @
2ad8622f
...
@@ -34,7 +34,7 @@ public enum AttackerCommand {
...
@@ -34,7 +34,7 @@ public enum AttackerCommand {
private
final
int
value
;
private
final
int
value
;
AttackerCommand
(
int
value
)
{
AttackerCommand
(
final
int
value
)
{
this
.
value
=
value
;
this
.
value
=
value
;
}
}
...
@@ -44,7 +44,7 @@ public enum AttackerCommand {
...
@@ -44,7 +44,7 @@ public enum AttackerCommand {
}
}
@JsonCreator
@JsonCreator
public
static
AttackerCommand
fromValue
(
int
value
)
{
public
static
AttackerCommand
fromValue
(
final
int
value
)
{
for
(
AttackerCommand
command
:
AttackerCommand
.
values
())
{
for
(
AttackerCommand
command
:
AttackerCommand
.
values
())
{
if
(
command
.
value
==
value
)
{
if
(
command
.
value
==
value
)
{
return
command
;
return
command
;
...
...
attacker/client/src/main/java/tech/pegasys/teku/attacker/AttackerResponse.java
View file @
2ad8622f
...
@@ -30,7 +30,7 @@ public class AttackerResponse {
...
@@ -30,7 +30,7 @@ public class AttackerResponse {
// Default constructor for Jackson deserialization
// Default constructor for Jackson deserialization
}
}
public
AttackerResponse
(
AttackerCommand
cmd
,
String
result
)
{
public
AttackerResponse
(
final
AttackerCommand
cmd
,
final
String
result
)
{
this
.
cmd
=
cmd
;
this
.
cmd
=
cmd
;
this
.
result
=
result
;
this
.
result
=
result
;
}
}
...
...
attacker/client/src/main/java/tech/pegasys/teku/attacker/JsonRpcClientUtil.java
View file @
2ad8622f
...
@@ -2,6 +2,7 @@ package tech.pegasys.teku.attacker;
...
@@ -2,6 +2,7 @@ package tech.pegasys.teku.attacker;
import
com.googlecode.jsonrpc4j.JsonRpcHttpClient
;
import
com.googlecode.jsonrpc4j.JsonRpcHttpClient
;
import
java.net.MalformedURLException
;
import
java.net.URI
;
import
java.net.URI
;
public
class
JsonRpcClientUtil
{
public
class
JsonRpcClientUtil
{
...
@@ -10,15 +11,22 @@ public class JsonRpcClientUtil {
...
@@ -10,15 +11,22 @@ public class JsonRpcClientUtil {
}
}
public
static
JsonRpcHttpClient
getJsonRpcClient
(){
public
static
JsonRpcHttpClient
getJsonRpcClient
(){
return
JsonRpcHttpClientSingleton
.
singleton
();
return
JsonRpcHttpClientSingleton
.
singleton
(
""
);
}
public
static
JsonRpcHttpClient
getJsonRpcClientByUrl
(
final
String
url
){
return
JsonRpcHttpClientSingleton
.
singleton
(
url
);
}
}
private
static
class
JsonRpcHttpClientSingleton
{
private
static
class
JsonRpcHttpClientSingleton
{
private
static
JsonRpcHttpClient
singleton
(){
private
static
JsonRpcHttpClient
singleton
(
final
String
url
){
JsonRpcHttpClient
client
=
null
;
JsonRpcHttpClient
client
=
null
;
try
{
try
{
client
=
new
JsonRpcHttpClient
(
URI
.
create
(
System
.
getenv
(
"ATTACKER_SERVICE_URL"
)).
toURL
());
String
real
=
url
;
}
catch
(
Exception
e
)
{
if
(
url
.
isEmpty
())
{
e
.
printStackTrace
();
real
=
System
.
getenv
(
"ATTACKER_SERVICE_URL"
);
}
client
=
new
JsonRpcHttpClient
(
URI
.
create
(
real
).
toURL
());
}
catch
(
MalformedURLException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
return
client
;
return
client
;
}
}
...
...
attacker/client/src/test/java/tech/pegasys/teku/attacker/AttackServiceTest.java
View file @
2ad8622f
...
@@ -2,16 +2,23 @@ package tech.pegasys.teku.attacker;
...
@@ -2,16 +2,23 @@ package tech.pegasys.teku.attacker;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
org.junit.jupiter.api.Test
;
import
tech.pegasys.teku.infrastructure.async.SafeFuture
;
import
java.util.concurrent.ExecutionException
;
public
class
AttackServiceTest
{
public
class
AttackServiceTest
{
private
AttackService
attackService
;
private
AttackService
attackService
;
@Test
@Test
public
void
blockGetNewParentRoot
()
{
public
void
blockGetNewParentRoot
()
throws
ExecutionException
,
InterruptedException
{
attackService
=
new
AttackService
(
"http://127.0.0.1:12000"
);
long
slot
=
1L
;
long
slot
=
1L
;
String
pub
=
""
;
String
pub
=
""
;
String
parentRoot
=
""
;
String
parentRoot
=
""
;
SafeFuture
<
AttackerResponse
>
attackerResponse
=
attackService
.
blockGetNewParentRoot
(
slot
,
pub
,
parentRoot
);
SafeFuture
<
AttackerResponse
>
attackerResponse
=
attackService
.
blockGetNewParentRoot
(
slot
,
pub
,
parentRoot
);
assertThat
(
attackerResponse
.
get
().
getCommond
().
getValue
).(
AttackerCommand
.
CMD_CONTINUE
.
getValue
()
s
);
assertThat
(
attackerResponse
.
get
().
getCmd
().
getValue
())
.
isEqualTo
(
AttackerCommand
.
CMD_NULL
.
getValue
());
}
}
}
}
\ 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