-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Fabio Di Fabio <[email protected]>
- Loading branch information
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
arithmetization/src/main/java/net/consensys/linea/extradata/LineaExtraDataHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Consensys Software Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package net.consensys.linea.extradata; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.tuweni.bytes.Bytes; | ||
import org.hyperledger.besu.plugin.data.AddedBlockContext; | ||
import org.hyperledger.besu.plugin.services.BesuEvents; | ||
|
||
@Slf4j | ||
public class LineaExtraDataHandler implements BesuEvents.BlockAddedListener { | ||
@Override | ||
public void onBlockAdded(final AddedBlockContext addedBlockContext) { | ||
final var blockHeader = addedBlockContext.getBlockHeader(); | ||
final var extraData = blockHeader.getExtraData(); | ||
|
||
if (!Bytes.EMPTY.equals(extraData)) { | ||
final byte version = extractVersion(extraData); | ||
switch (version) { | ||
case 1: | ||
parseVersion1(extraData); | ||
break; | ||
default: | ||
log.warn( | ||
"unsupported extra data version: {}, raw extra data field", | ||
version, | ||
extraData.toHexString()); | ||
} | ||
} | ||
} | ||
|
||
private void parseVersion1(final Bytes extraData) { | ||
log.info("Found extra data version 1: {}", extraData.toHexString()); | ||
} | ||
|
||
private byte extractVersion(final Bytes extraData) { | ||
return extraData.get(0); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
arithmetization/src/main/java/net/consensys/linea/extradata/LineaExtraDataPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright Consensys Software Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package net.consensys.linea.extradata; | ||
|
||
import java.util.Optional; | ||
|
||
import com.google.auto.service.AutoService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.consensys.linea.AbstractLineaRequiredPlugin; | ||
import org.hyperledger.besu.plugin.BesuContext; | ||
import org.hyperledger.besu.plugin.BesuPlugin; | ||
import org.hyperledger.besu.plugin.services.BesuEvents; | ||
|
||
/** This plugin registers handlers that are activated when new blocks are imported */ | ||
@Slf4j | ||
@AutoService(BesuPlugin.class) | ||
public class LineaExtraDataPlugin extends AbstractLineaRequiredPlugin { | ||
public static final String NAME = "linea"; | ||
private BesuEvents besuEventsService; | ||
|
||
@Override | ||
public Optional<String> getName() { | ||
return Optional.of(NAME); | ||
} | ||
|
||
@Override | ||
public void doRegister(final BesuContext context) { | ||
besuEventsService = | ||
context | ||
.getService(BesuEvents.class) | ||
.orElseThrow( | ||
() -> new RuntimeException("Failed to obtain BesuEvents from the BesuContext.")); | ||
} | ||
|
||
@Override | ||
public void beforeExternalServices() { | ||
super.beforeExternalServices(); | ||
besuEventsService.addBlockAddedListener(new LineaExtraDataHandler()); | ||
} | ||
} |