Skip to content

Commit

Permalink
Merge branch 'main' into siliev/change-xchain-messages
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanIliev545 committed Jan 16, 2025
2 parents cb673ae + f3a950c commit d94ee7d
Show file tree
Hide file tree
Showing 88 changed files with 2,030 additions and 1,441 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/manual-deploy-testnet-l2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,40 @@ jobs:
grant-sequencers.out
retention-days: 7

set-challenge-period:
needs:
- build
- check-obscuro-is-healthy
runs-on: ubuntu-latest
environment:
name: ${{ github.event.inputs.testnet_type }}
steps:
- uses: actions/checkout@v4

- name: 'Set challenge period on management contract'
id: setChallengePeriod
shell: bash
run: |
go run ./testnet/launcher/l1challengeperiod/cmd \
-l1_http_url=${{ secrets.L1_HTTP_URL }} \
-private_key=${{ secrets.ACCOUNT_PK_WORKER }} \
-management_contract_addr=${{ needs.build.outputs.MGMT_CONTRACT_ADDR }} \
-docker_image=${{ vars.L2_HARDHATDEPLOYER_DOCKER_BUILD_TAG }} \
-l1_challenge_period=${{ vars.L1_CHALLENGE_PERIOD }} \
echo "Setting challenge period to ${{ vars.L1_CHALLENGE_PERIOD }}"
- name: 'Save challenge period container logs'
run: |
docker logs `docker ps -aqf "name=set-challenge-period"` > set-challenge-period.out 2>&1
- name: 'Upload challenge period container logs'
uses: actions/upload-artifact@v4
with:
name: set-challenge-period
path: |
set-challenge-period.out
retention-days: 7

deploy-l2-contracts:
needs:
- build
Expand Down
56 changes: 54 additions & 2 deletions contracts/generated/ManagementContract/ManagementContract.go

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions contracts/scripts/delay/001_set_challenge_period.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ethers } from "hardhat";
import { ManagementContract } from "../../typechain-types";

const setChallengePeriod = async function (mgmtContractAddr: string, challengPeriod: number) {
const managementContract = await ethers.getContractAt(
"ManagementContract",
mgmtContractAddr
) as ManagementContract;


console.log(`Setting challenge period to: ${challengPeriod}`);
const tx = await managementContract.SetChallengePeriod(BigInt(challengPeriod));
await tx.wait();
console.log(`Successfully set challenge period to: ${challengPeriod}`);

const mgmtContractChallengePeriod = await managementContract.GetChallengePeriod();
if (BigInt(challengPeriod) !== mgmtContractChallengePeriod) {
throw new Error(`Failed to set the challenge period to: ${challengPeriod}. Returned value is: ${mgmtContractChallengePeriod}`);
}
}

const mgmtContractAddr = process.env.MGMT_CONTRACT_ADDRESS;
const challengePeriod = process.env.L1_CHALLENGE_PERIOD ?
Number(process.env.L1_CHALLENGE_PERIOD) : 0;


if (!mgmtContractAddr) {
console.error("Missing required environment variables: MGMT_CONTRACT_ADDRESS");
process.exit(1);
}

setChallengePeriod(mgmtContractAddr, challengePeriod)
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

export default setChallengePeriod;
15 changes: 13 additions & 2 deletions contracts/src/management/ManagementContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ contract ManagementContract is Initializable, OwnableUpgradeable {

bytes32 public lastBatchHash;

uint256 private challengePeriod;

function initialize() public initializer {
__Ownable_init(msg.sender);
lastBatchSeqNo = 0;
Expand Down Expand Up @@ -92,7 +94,6 @@ contract ManagementContract is Initializable, OwnableUpgradeable {
return isBundleSaved[bundleHash];
}

// TODO: ensure challenge period is added on top of block timestamp.
function pushCrossChainMessages(Structs.HeaderCrossChainData calldata crossChainData) internal {
uint256 messagesLength = crossChainData.messages.length;
for (uint256 i = 0; i < messagesLength; ++i) {
Expand Down Expand Up @@ -225,4 +226,14 @@ contract ManagementContract is Initializable, OwnableUpgradeable {
function GetImportantContractKeys() public view returns(string[] memory) {
return importantContractKeys;
}
}

// Return the challenge period delay for message bus root
function GetChallengePeriod() public view returns (uint256) {
return challengePeriod;
}

// Sets the challenge period for message bus root (owner only)
function SetChallengePeriod(uint256 _delay) public onlyOwner {
challengePeriod = _delay;
}
}
3 changes: 0 additions & 3 deletions go/common/enclave.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ type EnclaveInit interface {

// EnclaveAdmin provides administrative functions for managing an enclave.
type EnclaveAdmin interface {
// AddSequencer - called by the host when a new sequencer is added to the management contract
AddSequencer(id EnclaveID, proof types.Receipt) SystemError

// MakeActive - backup sequencer enclave can become active at the command of the host
MakeActive() SystemError

Expand Down
22 changes: 0 additions & 22 deletions go/common/encoding.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
package common

import (
"fmt"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
)

// EncodedL1Block the encoded version of an L1 block.
type EncodedL1Block []byte

func EncodeBlock(b *types.Block) (EncodedL1Block, error) {
encoded, err := rlp.EncodeToBytes(b)
if err != nil {
return nil, fmt.Errorf("could not encode block to bytes. Cause: %w", err)
}
return encoded, nil
}

func (eb EncodedL1Block) DecodeBlock() (*types.Block, error) {
b := types.Block{}
if err := rlp.DecodeBytes(eb, &b); err != nil {
return nil, fmt.Errorf("could not decode block from bytes. Cause: %w", err)
}
return &b, nil
}

func EncodeRollup(r *ExtRollup) (EncodedRollup, error) {
return rlp.EncodeToBytes(r)
}
Expand Down
4 changes: 3 additions & 1 deletion go/common/gethencoding/geth_encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"time"
"unsafe"

"github.com/ten-protocol/go-ten/go/common/gethutil"

gethlog "github.com/ethereum/go-ethereum/log"
"github.com/ten-protocol/go-ten/go/common/log"
"github.com/ten-protocol/go-ten/go/enclave/storage"
Expand Down Expand Up @@ -288,7 +290,7 @@ func (enc *gethEncodingServiceImpl) CreateEthHeaderForBatch(ctx context.Context,

gethHeader := types.Header{
ParentHash: convertedParentHash,
UncleHash: gethcommon.Hash{},
UncleHash: gethutil.EmptyHash,
Root: h.Root,
TxHash: h.TxHash,
ReceiptHash: h.ReceiptHash,
Expand Down
12 changes: 7 additions & 5 deletions go/common/gethutil/gethutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ import (
"context"
"fmt"

"github.com/ten-protocol/go-ten/go/enclave/storage"

gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ten-protocol/go-ten/go/common"
)

// Utilities for working with geth structures

type BlockResolver interface {
FetchBlock(ctx context.Context, blockHash common.L1BlockHash) (*types.Header, error)
}

// EmptyHash is useful for comparisons to check if hash has been set
var EmptyHash = gethcommon.Hash{}

// LCA - returns the latest common ancestor of the 2 blocks or an error if no common ancestor is found
// it also returns the blocks that became canonical, and the once that are now the fork
func LCA(ctx context.Context, newCanonical *types.Header, oldCanonical *types.Header, resolver storage.BlockResolver) (*common.ChainFork, error) {
func LCA(ctx context.Context, newCanonical *types.Header, oldCanonical *types.Header, resolver BlockResolver) (*common.ChainFork, error) {
b, cp, ncp, err := internalLCA(ctx, newCanonical, oldCanonical, resolver, []common.L1BlockHash{}, []common.L1BlockHash{})
return &common.ChainFork{
NewCanonical: newCanonical,
Expand All @@ -29,9 +31,9 @@ func LCA(ctx context.Context, newCanonical *types.Header, oldCanonical *types.He
}, err
}

func internalLCA(ctx context.Context, newCanonical *types.Header, oldCanonical *types.Header, resolver storage.BlockResolver, canonicalPath []common.L1BlockHash, nonCanonicalPath []common.L1BlockHash) (*types.Header, []common.L1BlockHash, []common.L1BlockHash, error) {
func internalLCA(ctx context.Context, newCanonical *types.Header, oldCanonical *types.Header, resolver BlockResolver, canonicalPath []common.L1BlockHash, nonCanonicalPath []common.L1BlockHash) (*types.Header, []common.L1BlockHash, []common.L1BlockHash, error) {
if newCanonical.Number.Uint64() == common.L1GenesisHeight || oldCanonical.Number.Uint64() == common.L1GenesisHeight {
return newCanonical, canonicalPath, nonCanonicalPath, nil
return oldCanonical, canonicalPath, nonCanonicalPath, nil
}
if newCanonical.Hash() == oldCanonical.Hash() {
// this is where we reach the common ancestor, which we add to the canonical path
Expand Down
6 changes: 0 additions & 6 deletions go/common/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package host
import (
"context"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ten-protocol/go-ten/go/common"
hostconfig "github.com/ten-protocol/go-ten/go/host/config"
"github.com/ten-protocol/go-ten/go/host/storage"
Expand Down Expand Up @@ -38,11 +37,6 @@ type Host interface {
NewHeadsChan() chan *common.BatchHeader
}

type BlockStream struct {
Stream <-chan *types.Block // the channel which will receive the consecutive, canonical blocks
Stop func() // function to permanently stop the stream and clean up any associated processes/resources
}

type BatchMsg struct {
Batches []*common.ExtBatch // The batches being sent.
IsLive bool // true if these batches are being sent as new, false if in response to a p2p request
Expand Down
8 changes: 4 additions & 4 deletions go/common/host/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,18 @@ type L1DataService interface {
// Subscribe will register a block handler to receive new blocks as they arrive, returns unsubscribe func
Subscribe(handler L1BlockHandler) func()

FetchBlockByHeight(height *big.Int) (*types.Block, error)
FetchBlockByHeight(height *big.Int) (*types.Header, error)
// FetchNextBlock returns the next canonical block after a given block hash
// It returns the new block, a bool which is true if the block is the current L1 head and a bool if the block is on a different fork to prevBlock
FetchNextBlock(prevBlock gethcommon.Hash) (*types.Block, bool, error)
FetchNextBlock(prevBlock gethcommon.Hash) (*types.Header, bool, error)
// GetTenRelevantTransactions returns the events and transactions relevant to Ten
GetTenRelevantTransactions(block *common.L1Block) (*common.ProcessedL1Data, error)
GetTenRelevantTransactions(block *types.Header) (*common.ProcessedL1Data, error)
}

// L1BlockHandler is an interface for receiving new blocks from the repository as they arrive
type L1BlockHandler interface {
// HandleBlock will be called in a new goroutine for each new block as it arrives
HandleBlock(block *types.Block)
HandleBlock(block *types.Header)
}

// L1Publisher provides an interface for the host to interact with Ten data (management contract etc.) on L1
Expand Down
2 changes: 2 additions & 0 deletions go/common/l1_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type L1InitializeSecretTx struct {
Attestation EncodedAttestationReport
}

type L1PermissionSeqTx struct{}

// The following types and structs are used for processing the l1 blocks and categorising the transactions to be processed
// by the enclave.

Expand Down
3 changes: 1 addition & 2 deletions go/common/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
BatchHeightKey = "batch_height"
BatchSeqNoKey = "batch_seq_num"
RollupHashKey = "rollup"
CmpKey = "component"
CmpKey = "cmp"
NodeIDKey = "node_id"
EnclaveIDKey = "enclave_id"
NetworkIDKey = "network_id"
Expand All @@ -34,7 +34,6 @@ const (
HostCmp = "host"
HostRPCCmp = "host_rpc"
TxInjectCmp = "tx_inject"
TestLogCmp = "test_log"
P2PCmp = "p2p"
RPCClientCmp = "rpc_client"
DeployerCmp = "deployer"
Expand Down
Loading

0 comments on commit d94ee7d

Please sign in to comment.