Skip to content

Commit 899f834

Browse files
authored
Merge branch 'master' into support-ipv6-discovery
2 parents 2279da9 + 77b1e42 commit 899f834

7 files changed

Lines changed: 119 additions & 94 deletions

File tree

.github/workflows/ci.yml

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@ jobs:
2222

2323
build:
2424
runs-on: ubuntu-24.04
25+
permissions:
26+
contents: read
2527
steps:
26-
- name: Checkout
27-
uses: actions/checkout@v6
28-
- name: Setup Java and Gradle
29-
id: setup-java-gradle
30-
uses: ConsenSys/github-actions/java-setup-gradle@main
28+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
29+
with:
30+
fetch-depth: 0
31+
- uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
32+
with:
33+
java-version: '21'
34+
distribution: 'temurin'
35+
- name: Setup Gradle
36+
uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c
3137
- name: Build
32-
run: ./gradlew --no-daemon --parallel build sourcesJar
38+
run: ./gradlew --no-daemon --parallel build
3339
- name: Upload test results
3440
uses: actions/upload-artifact@v7
3541
if: always()
@@ -47,21 +53,25 @@ jobs:
4753
retention-days: 7
4854

4955
publish:
50-
needs: build
56+
needs: [build]
5157
environment: publish
58+
if: startsWith(github.ref, 'refs/tags/')
5259
runs-on: ubuntu-24.04
53-
if: |
54-
github.ref == 'refs/heads/master' ||
55-
startsWith(github.ref, 'refs/heads/release-') ||
56-
startsWith(github.ref, 'refs/tags/')
5760
steps:
58-
- name: Checkout
59-
uses: actions/checkout@v6
60-
- name: Setup Java and Gradle
61-
id: setup-java-gradle
62-
uses: ConsenSys/github-actions/java-setup-gradle@main
61+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
62+
with:
63+
fetch-depth: 0
64+
- uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
65+
with:
66+
java-version: '21'
67+
distribution: 'temurin'
68+
- name: Setup Gradle
69+
uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c
6370
- name: Publish
6471
env:
65-
CLOUDSMITH_USER: ${{ secrets.CLOUDSMITH_USER }}
66-
CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
67-
run: ./gradlew --no-daemon --parallel publish
72+
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.JRELEASER_MAVENCENTRAL_USERNAME }}
73+
JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.JRELEASER_MAVENCENTRAL_PASSWORD }}
74+
JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
75+
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
76+
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
77+
run: ./gradlew --no-daemon --parallel publish jreleaserFullRelease

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*.log
88
*.db
99
.classpath
10+
.factorypath
1011
.DS_Store
1112
.gradletasknamecache
1213
.externalToolBuilders/

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# discovery
22

33
[![ci](https://github.com/Consensys/discovery/actions/workflows/ci.yml/badge.svg)](https://github.com/Consensys/discovery/actions/workflows/ci.yml)
4-
[![Latest version of 'discovery' @ Cloudsmith](https://api-prd.cloudsmith.io/v1/badges/version/consensys/maven/maven/discovery/latest/a=noarch;xg=tech.pegasys.discovery/?render=true&show_latest=true)](https://cloudsmith.io/~consensys/repos/maven/packages/detail/maven/discovery/latest/a=noarch;xg=tech.pegasys.discovery/)
4+
[![Maven Central](https://img.shields.io/maven-central/v/io.consensys.protocols/discovery)](https://central.sonatype.com/artifact/io.consensys.protocols/discovery)
55

66
## Overview
77

@@ -12,10 +12,10 @@ peer discovery protocol.
1212

1313
```groovy
1414
repositories {
15-
maven { url "https://artifacts.consensys.net/public/maven/maven/" }
15+
mavenCentral()
1616
}
1717
1818
dependencies {
19-
implementation("tech.pegasys:discovery:<version>")
19+
implementation("io.consensys.protocols:discovery:<version>")
2020
}
2121
```

build.gradle

Lines changed: 82 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,46 @@
1-
//discovery v5
1+
buildscript {
2+
configurations.classpath {
3+
// Force JGit 6.x to resolve conflict between git-versioning (7.x) and JReleaser (5.x)
4+
// JGit 7.x removed GpgObjectSigner which JReleaser still references
5+
// See: https://github.com/jreleaser/jreleaser/discussions/1897
6+
resolutionStrategy.force 'org.eclipse.jgit:org.eclipse.jgit:6.10.0.202406032230-r'
7+
}
8+
}
29

310
plugins {
411
id 'java-library'
12+
id 'maven-publish'
513
id 'com.diffplug.spotless' version '6.25.0'
614
id 'com.github.ben-manes.versions' version '0.51.0'
715
id 'com.github.hierynomus.license' version '0.16.1'
816
id 'io.spring.dependency-management' version '1.1.5'
9-
id 'net.ltgt.errorprone' version '4.0.1'
10-
id 'org.ajoberstar.grgit' version '5.2.2'
17+
id 'net.ltgt.errorprone' version '5.1.0'
18+
id 'me.qoomon.git-versioning' version '6.4.4'
19+
id 'org.jreleaser' version '1.23.0'
1120
}
1221

13-
rootProject.version = calculatePublishVersion()
14-
def specificVersion = calculateVersion()
22+
group = "io.consensys.protocols"
23+
version = "UNKNOWN"
24+
25+
gitVersioning.apply {
26+
refs {
27+
tag(".+") {
28+
version = "\${ref}"
29+
}
30+
branch("master") {
31+
version = "develop"
32+
}
33+
branch("release-.+") {
34+
version = "\${ref}-develop"
35+
}
36+
branch(".+") {
37+
version = "\${ref}"
38+
}
39+
}
40+
rev {
41+
version = "UNKNOWN"
42+
}
43+
}
1544

1645
apply from: "${rootDir}/gradle/versions.gradle"
1746
apply from: "${rootDir}/gradle/check-licenses.gradle"
@@ -48,7 +77,7 @@ dependencies {
4877
testRuntimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl'
4978

5079
errorprone("com.google.errorprone:error_prone_core")
51-
errorprone("tech.pegasys.tools.epchecks:errorprone-checks")
80+
errorprone("io.consensys.protocols:errorprone-checks")
5281
}
5382

5483
spotless {
@@ -104,6 +133,8 @@ tasks.withType(JavaCompile) {
104133
check('CanIgnoreReturnValueSuggester', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
105134
// We prefer to be more explicit in address selection especially in tests, so removing this check
106135
check('AddressSelection', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
136+
// Interface constant initializing a subclass is intentional in IdentitySchemaInterpreter
137+
check('ClassInitializationDeadlock', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
107138

108139
// These are experimental checks that we want enabled.
109140
check('MissingBraces', net.ltgt.gradle.errorprone.CheckSeverity.WARN)
@@ -135,12 +166,17 @@ tasks.withType(JavaCompile) {
135166
'Specification-Title': project.name,
136167
'Specification-Version': project.version,
137168
'Implementation-Title': project.name,
138-
'Implementation-Version': specificVersion
169+
'Implementation-Version': project.version
139170
)
140171
}
141172
}
142173
}
143174

175+
java {
176+
withJavadocJar()
177+
withSourcesJar()
178+
}
179+
144180
test {
145181
jvmArgs = [
146182
'-Xmx4g',
@@ -153,57 +189,43 @@ test {
153189
}
154190

155191
javadoc {
156-
options.addStringOption('Xdoclint:all', '-quiet')
192+
options.addStringOption('Xdoclint:all,-missing', '-quiet')
157193
options.addStringOption('Xwerror', '-html5')
158194
options.encoding = 'UTF-8'
159195
}
160196

161-
task sourcesJar(type: Jar, dependsOn: classes) {
162-
archiveClassifier = 'sources'
163-
from sourceSets.main.allSource
164-
}
165-
166197
task runTestDiscovery(type:JavaExec) {
167198
mainClass = 'org.ethereum.beacon.discovery.app.DiscoveryTestServer'
168199
classpath = sourceSets.main.runtimeClasspath + sourceSets.test.runtimeClasspath
169200
systemProperty "log4j.configurationFile", "log4j2-test-discovery.xml"
170201
}
171202

172-
def cloudsmithUser = project.hasProperty('cloudsmithUser') ? project.property('cloudsmithUser') : System.getenv('CLOUDSMITH_USER')
173-
def cloudsmithKey = project.hasProperty('cloudsmithApiKey') ? project.property('cloudsmithApiKey') : System.getenv('CLOUDSMITH_API_KEY')
174-
175-
apply plugin: 'maven-publish'
176203
publishing {
177-
repositories {
178-
maven {
179-
name = "cloudsmith"
180-
url = "https://api-g.cloudsmith.io/maven/consensys/maven/"
181-
credentials {
182-
username = cloudsmithUser
183-
password = cloudsmithKey
184-
}
185-
}
186-
}
187204
publications {
188205
mavenJava(MavenPublication) {
189-
groupId "tech.pegasys.discovery"
190-
version project.version
206+
groupId "io.consensys.protocols"
191207
from components.java
192-
artifact sourcesJar
193-
194208
versionMapping {
195209
usage('java-api') { fromResolutionOf('runtimeClasspath') }
196210
usage('java-runtime') { fromResolutionResult() }
197211
}
198212
pom {
199213
name = "${project.name}"
200-
url = 'http://github.com/ConsenSys/discovery'
214+
description = 'Java implementation of the Ethereum Discovery v5 protocol'
215+
url = 'https://github.com/ConsenSys/discovery'
201216
licenses {
202217
license {
203218
name = 'The Apache License, Version 2.0'
204219
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
205220
}
206221
}
222+
developers {
223+
developer {
224+
id = "consensys"
225+
name = "Protocols Team"
226+
email = "devops@consensys.net"
227+
}
228+
}
207229
scm {
208230
connection = 'scm:git:git://github.com/ConsenSys/discovery.git'
209231
developerConnection = 'scm:git:ssh://github.com/ConsenSys/discovery.git'
@@ -212,46 +234,38 @@ publishing {
212234
}
213235
}
214236
}
215-
}
216-
217-
218-
// Calculate the version that this build would be published under (if it is published)
219-
// If this exact commit is tagged, use the tag
220-
// If this is on a release-* branch, use the most recent tag appended with +develop (e.g. 0.1.1-RC1+develop)
221-
// Otherwise, use develop
222-
def calculatePublishVersion() {
223-
if (!grgit) {
224-
return 'UNKNOWN'
225-
}
226-
def specificVersion = calculateVersion()
227-
def isReleaseBranch = grgit.branch.current().name.startsWith('release-')
228-
if (specificVersion.contains('+')) {
229-
return isReleaseBranch ? "${specificVersion.substring(0, specificVersion.indexOf('+'))}+develop" : "develop"
237+
repositories {
238+
maven {
239+
url = layout.buildDirectory.dir("staging-deploy")
240+
}
230241
}
231-
return specificVersion
232242
}
233243

234-
// Calculate the version that teku --version will report (among other places)
235-
// If this exact commit is tagged, use the tag
236-
// Otherwise use git describe --tags and replace the - after the tag with a +
237-
def calculateVersion() {
238-
if (!grgit) {
239-
return 'UNKNOWN'
240-
}
241-
String version = grgit.describe(tags: true)
242-
if (version == null) {
243-
return "UNKNOWN+g${grgit.head().abbreviatedId}"
244+
jreleaser {
245+
release {
246+
github {
247+
// Creating and tagging a release is done manually
248+
skipRelease = true
249+
skipTag = true
250+
// injecting a fake value to make JReleaser happy
251+
token = "foobar"
252+
}
244253
}
245-
def versionPattern = ~/^(?<lastVersion>.*)-(?<devVersion>[0-9]+-g[a-z0-9]+)$/
246-
def matcher = version =~ versionPattern
247-
if (matcher.find()) {
248-
return "${matcher.group("lastVersion")}+${matcher.group("devVersion")}"
254+
signing {
255+
active = 'ALWAYS'
256+
armored = true
249257
}
250-
return version
251-
}
252-
253-
task printVersion() {
254-
doFirst {
255-
print "Specific version: ${specificVersion} Publish version: ${project.version}"
258+
deploy {
259+
maven {
260+
mavenCentral {
261+
sonatype {
262+
active = 'ALWAYS'
263+
url = 'https://central.sonatype.com/api/v1/publisher'
264+
stagingRepository('build/staging-deploy')
265+
retryDelay = 15
266+
maxRetries = 100
267+
}
268+
}
269+
}
256270
}
257271
}

gradle/versions.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
dependencyManagement {
22
dependencies {
3-
dependencySet(group: 'com.google.errorprone', version: '2.28.0') {
3+
dependencySet(group: 'com.google.errorprone', version: '2.36.0') {
44
entry 'error_prone_annotation'
55
entry 'error_prone_check_api'
66
entry 'error_prone_core'
77
entry 'error_prone_test_helpers'
88
}
99

10-
dependency 'tech.pegasys.tools.epchecks:errorprone-checks:1.1.1'
10+
dependency 'io.consensys.protocols:errorprone-checks:1.1.2'
1111

1212
dependency 'com.google.guava:guava:33.2.1-jre'
1313

src/main/java/org/ethereum/beacon/discovery/database/ExpirationSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Set-alike collection with data expiring in configured time. This structure is not thread safe,
1919
* please, synchronize usage
2020
*
21-
* @param <V> data type should extend Comparable<V> to avoid collisions
21+
* @param <V> data type should extend {@code Comparable<V>} to avoid collisions
2222
*/
2323
public class ExpirationSet<V extends Comparable<V>> {
2424

src/main/java/org/ethereum/beacon/discovery/scheduler/ExpirationScheduler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
/**
1414
* Schedules `runnable` in delay which is set by constructor. When runnable is renewed by putting it
15-
* in map again, old task is cancelled and removed. Task are equalled by the <Key>
15+
* in map again, old task is cancelled and removed. Task are equalled by the {@code Key}
1616
*/
1717
public class ExpirationScheduler<Key> {
1818
private final ScheduledExecutorService scheduler;

0 commit comments

Comments
 (0)