Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into matt/write-contract-a…
Browse files Browse the repository at this point in the history
…ddresses-on-deploy
  • Loading branch information
BedrockSquirrel committed Nov 22, 2023
2 parents 38110e5 + 1248086 commit 26e46ed
Show file tree
Hide file tree
Showing 30 changed files with 600 additions and 141 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/manual-deploy-testnet-l2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ jobs:
- name: 'Send a repository dispatch to obscuro-test on deployment of dev-testnet'
if: ${{ (github.event.inputs.testnet_type == 'dev-testnet') }}
run: |
curl -XPOST -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" -H "Accept:application/vnd.github" -H "Content-Type:application/json" https://api.github.com/repos/obscuronet/obscuro-test/dispatches --data '{ "event_type": "dev_testnet_deployed", "client_payload": { "ref": "${{ github.ref_name }}" }'
curl -XPOST -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" -H "Accept:application/vnd.github" -H "Content-Type:application/json" https://api.github.com/repos/ten-protocol/ten-test/dispatches --data '{ "event_type": "dev_testnet_deployed", "client_payload": { "ref": "${{ github.ref_name }}" }'
- name: 'Send a repository dispatch to obscuro-test on deployment of testnet'
if: ${{ (github.event.inputs.testnet_type == 'uat-testnet') }}
run: |
curl -XPOST -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" -H "Accept:application/vnd.github" -H "Content-Type:application/json" https://api.github.com/repos/obscuronet/obscuro-test/dispatches --data '{ "event_type": "uat_testnet_deployed", "client_payload": { "ref": "${{ github.ref_name }}" }'
curl -XPOST -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" -H "Accept:application/vnd.github" -H "Content-Type:application/json" https://api.github.com/repos/ten-protocol/ten-test/dispatches --data '{ "event_type": "uat_testnet_deployed", "client_payload": { "ref": "${{ github.ref_name }}" }'
6 changes: 3 additions & 3 deletions .github/workflows/manual-upgrade-testnet-l2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,12 @@ jobs:
- name: 'Send a repository dispatch to obscuro-test on upgrade of dev-testnet'
if: ${{ github.event.inputs.testnet_type == 'dev-testnet' }}
run: |
curl -XPOST -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" -H "Accept:application/vnd.github" -H "Content-Type:application/json" https://api.github.com/repos/obscuronet/obscuro-test/dispatches --data '{ "event_type": "dev_testnet_upgraded", "client_payload": { "ref": "${{ github.ref_name }}" }'
curl -XPOST -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" -H "Accept:application/vnd.github" -H "Content-Type:application/json" https://api.github.com/repos/ten-protocol/ten-test/dispatches --data '{ "event_type": "dev_testnet_upgraded", "client_payload": { "ref": "${{ github.ref_name }}" }'
- name: 'Send a repository dispatch to obscuro-test on upgrade of uat-testnet'
if: ${{ github.event.inputs.testnet_type == 'uat-testnet' }}
run: |
curl -XPOST -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" -H "Accept:application/vnd.github" -H "Content-Type:application/json" https://api.github.com/repos/obscuronet/obscuro-test/dispatches --data '{ "event_type": "uat_testnet_upgraded", "client_payload": { "ref": "${{ github.ref_name }}" }'
curl -XPOST -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" -H "Accept:application/vnd.github" -H "Content-Type:application/json" https://api.github.com/repos/ten-protocol/ten-test/dispatches --data '{ "event_type": "uat_testnet_upgraded", "client_payload": { "ref": "${{ github.ref_name }}" }'
obscuro-test-signal-on-schedule:
runs-on: ubuntu-latest
Expand All @@ -228,4 +228,4 @@ jobs:
steps:
- name: 'Send a repository dispatch to obscuro-test on upgrade of dev-testnet'
run: |
curl -XPOST -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" -H "Accept:application/vnd.github" -H "Content-Type:application/json" https://api.github.com/repos/obscuronet/obscuro-test/dispatches --data '{ "event_type": "dev_testnet_upgraded", "client_payload": { "ref": "${{ github.ref_name }}" }'
curl -XPOST -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" -H "Accept:application/vnd.github" -H "Content-Type:application/json" https://api.github.com/repos/ten-protocol/ten-test/dispatches --data '{ "event_type": "dev_testnet_upgraded", "client_payload": { "ref": "${{ github.ref_name }}" }'
2 changes: 1 addition & 1 deletion .github/workflows/on-merged-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ jobs:
steps:
- name: 'Trigger obscuro-test local testnet tun'
run: |
curl -XPOST -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" -H "Accept:application/vnd.github" -H "Content-Type:application/json" https://api.github.com/repos/obscuronet/obscuro-test/dispatches --data '{ "event_type": "merged_pull_request", "client_payload": { "number": ${{ github.event.number }}, "owner": "${{ github.event.pull_request.user.login }}" } }'
curl -XPOST -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" -H "Accept:application/vnd.github" -H "Content-Type:application/json" https://api.github.com/repos/ten-protocol/ten-test/dispatches --data '{ "event_type": "merged_pull_request", "client_payload": { "number": ${{ github.event.number }}, "owner": "${{ github.event.pull_request.user.login }}" } }'
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// Deploy a constant supply (constructor mints) erc20
await deployments.execute('ObscuroBridge', {
from: deployer
}, 'promoteToAdmin', '0xE09a37ABc1A63441404007019E5BC7517bE2c43f')
}, 'promoteToAdmin', '0xE09a37ABc1A63441404007019E5BC7517bE2c43f');

await deployments.execute('ObscuroBridge', {
from: deployer
}, 'promoteToAdmin', '0xeC3f9B38a3B30AdC9fB3dF3a0D8f50127E6c2C8f');
};

export default func;
Expand Down
94 changes: 73 additions & 21 deletions go/common/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"math/big"
"sync"

"github.com/ethereum/go-ethereum/common/hexutil"

"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ten-protocol/go-ten/contracts/generated/MessageBus"
"golang.org/x/crypto/sha3"
)
Expand Down Expand Up @@ -45,32 +46,83 @@ type BatchHeader struct {
TransfersTree common.Hash `json:"transfersTree"` // This is a merkle tree of all of the outbound value transfers for the MainNet
}

type batchHeaderEncoding struct {
ParentHash L2BatchHash `json:"parentHash"`
Root common.Hash `json:"stateRoot"`
TxHash common.Hash `json:"transactionsRoot"`
ReceiptHash common.Hash `json:"receiptsRoot"`
Number *hexutil.Big `json:"number"`
SequencerOrderNo *hexutil.Big `json:"sequencerOrderNo"`
GasLimit hexutil.Uint64 `json:"gasLimit"`
GasUsed hexutil.Uint64 `json:"gasUsed"`
Time hexutil.Uint64 `json:"timestamp"`
Extra []byte `json:"extraData"`
BaseFee *hexutil.Big `json:"baseFeePerGas"`
Coinbase *common.Address `json:"miner"`

// The custom Obscuro fields.
L1Proof L1BlockHash `json:"l1Proof"` // the L1 block used by the enclave to generate the current batch
R, S *hexutil.Big // signature values
CrossChainMessages []MessageBus.StructsCrossChainMessage `json:"crossChainMessages"`
LatestInboundCrossChainHash common.Hash `json:"inboundCrossChainHash"` // The block hash of the latest block that has been scanned for cross chain messages.
LatestInboundCrossChainHeight *hexutil.Big `json:"inboundCrossChainHeight"` // The block height of the latest block that has been scanned for cross chain messages.
TransfersTree common.Hash
}

// MarshalJSON custom marshals the BatchHeader into a json
func (b *BatchHeader) MarshalJSON() ([]byte, error) {
type Alias BatchHeader
return json.Marshal(struct {
*Alias
Hash common.Hash `json:"hash"`
UncleHash *common.Hash `json:"sha3Uncles"`
Coinbase *common.Address `json:"miner"`
Bloom *types.Bloom `json:"logsBloom"`
Difficulty *big.Int `json:"difficulty"`
Nonce *types.BlockNonce `json:"nonce"`

// BaseFee was added by EIP-1559 and is ignored in legacy headers.
BaseFee *big.Int `json:"baseFeePerGas"`
}{
(*Alias)(b),
b.Hash(),
nil,
return json.Marshal(batchHeaderEncoding{
b.ParentHash,
b.Root,
b.TxHash,
b.ReceiptHash,
(*hexutil.Big)(b.Number),
(*hexutil.Big)(b.SequencerOrderNo),
hexutil.Uint64(b.GasLimit),
hexutil.Uint64(b.GasUsed),
hexutil.Uint64(b.Time),
b.Extra,
(*hexutil.Big)(b.BaseFee),
&b.Coinbase,
nil,
nil,
nil,
b.BaseFee,
b.L1Proof,
(*hexutil.Big)(b.R),
(*hexutil.Big)(b.S),
b.CrossChainMessages,
b.LatestInboundCrossChainHash,
(*hexutil.Big)(b.LatestInboundCrossChainHeight),
b.TransfersTree,
})
}

func (b *BatchHeader) UnmarshalJSON(data []byte) error {
dec := new(batchHeaderEncoding)
err := json.Unmarshal(data, dec)
if err != nil {
return err
}

b.ParentHash = dec.ParentHash
b.Root = dec.Root
b.TxHash = dec.TxHash
b.ReceiptHash = dec.ReceiptHash
b.Number = (*big.Int)(dec.Number)
b.SequencerOrderNo = (*big.Int)(dec.SequencerOrderNo)
b.GasLimit = uint64(dec.GasLimit)
b.GasUsed = uint64(dec.GasUsed)
b.Time = uint64(dec.Time)
b.Extra = dec.Extra
b.BaseFee = (*big.Int)(dec.BaseFee)
b.Coinbase = *dec.Coinbase
b.L1Proof = dec.L1Proof
b.R = (*big.Int)(dec.R)
b.S = (*big.Int)(dec.S)
b.CrossChainMessages = dec.CrossChainMessages
b.LatestInboundCrossChainHash = dec.LatestInboundCrossChainHash
b.LatestInboundCrossChainHeight = (*big.Int)(dec.LatestInboundCrossChainHeight)
b.TransfersTree = dec.TransfersTree
return nil
}

// RollupHeader is a public / plaintext struct that holds common properties of rollups.
// All these fields are processed by the Management contract
type RollupHeader struct {
Expand Down
2 changes: 1 addition & 1 deletion go/common/headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestBatchHeader_MarshalJSON(t *testing.T) {
Root: randomHash(),
TxHash: randomHash(),
ReceiptHash: randomHash(),
Number: gethcommon.Big0,
Number: gethcommon.Big1,
SequencerOrderNo: gethcommon.Big1,
GasLimit: 100,
GasUsed: 200,
Expand Down
11 changes: 7 additions & 4 deletions go/common/host/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,8 @@ type L1Publisher interface {
InitializeSecret(attestation *common.AttestationReport, encSecret common.EncryptedSharedEnclaveSecret) error
// RequestSecret will send a management contract transaction to request a secret from the enclave, returning the L1 head at time of sending
RequestSecret(report *common.AttestationReport) (gethcommon.Hash, error)
// ExtractSecretResponses will return all secret response tx from an L1 block
ExtractSecretResponses(block *types.Block) []*ethadapter.L1RespondSecretTx
// ExtractRollupTxs will return all rollup txs from an L1 block
ExtractRollupTxs(block *types.Block) []*ethadapter.L1RollupTx
// ExtractObscuroRelevantTransactions will return all Obscuro relevant tx from an L1 block
ExtractObscuroRelevantTransactions(block *types.Block) ([]*ethadapter.L1RespondSecretTx, []*ethadapter.L1RollupTx, []*ethadapter.L1SetImportantContractsTx)
// PublishRollup will create and publish a rollup tx to the management contract - fire and forget we don't wait for receipt
// todo (#1624) - With a single sequencer, it is problematic if rollup publication fails; handle this case better
PublishRollup(producedRollup *common.ExtRollup)
Expand All @@ -114,6 +112,11 @@ type L1Publisher interface {
FetchLatestPeersList() ([]string, error)

FetchLatestSeqNo() (*big.Int, error)

// GetImportantContracts returns a (cached) record of addresses of the important network contracts
GetImportantContracts() map[string]gethcommon.Address
// ResyncImportantContracts will fetch the latest important contracts from the management contract, update the cache
ResyncImportantContracts() error
}

// L2BatchRepository provides an interface for the host to request L2 batch data (live-streaming and historical)
Expand Down
1 change: 1 addition & 0 deletions go/common/query_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,5 @@ type ObscuroNetworkInfo struct {
L1StartHash common.Hash
SequencerID common.Address
MessageBusAddress common.Address
ImportantContracts map[string]common.Address // map of contract name to address
}
11 changes: 4 additions & 7 deletions go/enclave/components/batch_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ func (executor *batchExecutor) ComputeBatch(context *BatchExecutionContext, fail
return nil, fmt.Errorf("failed adding cross chain data to batch. Cause: %w", err)
}

executor.populateHeader(&copyBatch, allReceipts(txReceipts, ccReceipts))
allReceipts := append(txReceipts, ccReceipts...)
executor.populateHeader(&copyBatch, allReceipts)
if failForEmptyBatch &&
len(txReceipts) == 0 &&
len(ccReceipts) == 0 &&
Expand All @@ -220,7 +221,7 @@ func (executor *batchExecutor) ComputeBatch(context *BatchExecutionContext, fail
}

// the logs and receipts produced by the EVM have the wrong hash which must be adjusted
for _, receipt := range txReceipts {
for _, receipt := range allReceipts {
receipt.BlockHash = copyBatch.Hash()
for _, l := range receipt.Logs {
l.BlockHash = copyBatch.Hash()
Expand All @@ -229,7 +230,7 @@ func (executor *batchExecutor) ComputeBatch(context *BatchExecutionContext, fail

return &ComputedBatch{
Batch: &copyBatch,
Receipts: txReceipts,
Receipts: allReceipts,
Commit: func(deleteEmptyObjects bool) (gethcommon.Hash, error) {
executor.stateDBMutex.Lock()
defer executor.stateDBMutex.Unlock()
Expand Down Expand Up @@ -429,10 +430,6 @@ func (executor *batchExecutor) processTransactions(
return executedTransactions, excludedTransactions, txReceipts, nil
}

func allReceipts(txReceipts []*types.Receipt, depositReceipts []*types.Receipt) types.Receipts {
return append(txReceipts, depositReceipts...)
}

type sortByTxIndex []*types.Receipt

func (c sortByTxIndex) Len() int { return len(c) }
Expand Down
44 changes: 36 additions & 8 deletions go/enclave/nodetype/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,33 @@ func (s *sequencer) createGenesisBatch(block *common.L1Block) error {
return err
}

// make sure the mempool queuing system is initialized before adding the msg bus tx to it
time.Sleep(time.Second)
// produce batch #2 which has the message bus and any other system contracts
cb, err := s.produceBatch(
batch.Header.SequencerOrderNo.Add(batch.Header.SequencerOrderNo, big.NewInt(1)),
block.Hash(),
batch.Hash(),
common.L2Transactions{msgBusTx},
uint64(time.Now().Unix()),
false,
)
if err != nil {
if errors.Is(err, components.ErrNoTransactionsToProcess) {
// skip batch production when there are no transactions to process
// todo: this might be a useful event to track for metrics (skipping batch production because empty batch)
s.logger.Debug("Skipping batch production, no transactions to execute")
return nil
}
return fmt.Errorf(" failed producing batch. Cause: %w", err)
}

if err = s.mempool.Add(msgBusTx); err != nil {
return fmt.Errorf("failed to queue message bus creation transaction to genesis - %w", err)
if len(cb.Receipts) == 0 || cb.Receipts[0].TxHash.Hex() != msgBusTx.Hash().Hex() {
err = fmt.Errorf("message Bus contract not minted - no receipts in batch")
s.logger.Error(err.Error())
return err
}

s.logger.Info("Message Bus Contract minted successfully", "address", cb.Receipts[0].ContractAddress.Hex())

return nil
}

Expand Down Expand Up @@ -232,7 +253,14 @@ func (s *sequencer) createNewHeadBatch(l1HeadBlock *common.L1Block, skipBatchIfE
return nil
}

func (s *sequencer) produceBatch(sequencerNo *big.Int, l1Hash common.L1BlockHash, headBatch common.L2BatchHash, transactions common.L2Transactions, batchTime uint64, failForEmptyBatch bool) (*core.Batch, error) {
func (s *sequencer) produceBatch(
sequencerNo *big.Int,
l1Hash common.L1BlockHash,
headBatch common.L2BatchHash,
transactions common.L2Transactions,
batchTime uint64,
failForEmptyBatch bool,
) (*components.ComputedBatch, error) {
cb, err := s.batchProducer.ComputeBatch(&components.BatchExecutionContext{
BlockPtr: l1Hash,
ParentPtr: headBatch,
Expand Down Expand Up @@ -268,7 +296,7 @@ func (s *sequencer) produceBatch(sequencerNo *big.Int, l1Hash common.L1BlockHash
return nil, fmt.Errorf("unable to remove tx from mempool - %w", err)
}

return cb.Batch, nil
return cb, nil
}

// StoreExecutedBatch - stores an executed batch in one go. This can be done for the sequencer because it is guaranteed
Expand Down Expand Up @@ -359,11 +387,11 @@ func (s *sequencer) duplicateBatches(l1Head *types.Block, nonCanonicalL1Path []c
}
sequencerNo = sequencerNo.Add(sequencerNo, big.NewInt(1))
// create the duplicate and store/broadcast it, recreate batch even if it was empty
b, err := s.produceBatch(sequencerNo, l1Head.ParentHash(), currentHead, orphanBatch.Transactions, orphanBatch.Header.Time, false)
cb, err := s.produceBatch(sequencerNo, l1Head.ParentHash(), currentHead, orphanBatch.Transactions, orphanBatch.Header.Time, false)
if err != nil {
return fmt.Errorf("could not produce batch. Cause %w", err)
}
currentHead = b.Hash()
currentHead = cb.Batch.Hash()
s.logger.Info("Duplicated batch", log.BatchHashKey, currentHead)
}

Expand Down
5 changes: 5 additions & 0 deletions go/ethadapter/l1_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ type L1RespondSecretTx struct {
HostAddress string
}

type L1SetImportantContractsTx struct {
Key string
NewAddress gethcommon.Address
}

// Sign signs the payload with a given private key
func (l *L1RespondSecretTx) Sign(privateKey *ecdsa.PrivateKey) *L1RespondSecretTx {
var data []byte
Expand Down
13 changes: 8 additions & 5 deletions go/ethadapter/mgmtcontractlib/mgmt_contract_ABI.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package mgmtcontractlib
import "github.com/ten-protocol/go-ten/contracts/generated/ManagementContract"

const (
AddRollupMethod = "AddRollup"
RespondSecretMethod = "RespondNetworkSecret"
RequestSecretMethod = "RequestNetworkSecret"
InitializeSecretMethod = "InitializeNetworkSecret" //#nosec
GetHostAddressesMethod = "GetHostAddresses"
AddRollupMethod = "AddRollup"
RespondSecretMethod = "RespondNetworkSecret"
RequestSecretMethod = "RequestNetworkSecret"
InitializeSecretMethod = "InitializeNetworkSecret" //#nosec
GetHostAddressesMethod = "GetHostAddresses"
GetImportantContractKeysMethod = "GetImportantContractKeys"
SetImportantContractsMethod = "SetImportantContractAddress"
GetImportantAddressMethod = "importantContractAddresses"
)

var MgmtContractABI = ManagementContract.ManagementContractMetaData.ABI
Loading

0 comments on commit 26e46ed

Please sign in to comment.