Skip to content

Commit

Permalink
Merge pull request #47 from astriaorg/noot/bridge-genesis
Browse files Browse the repository at this point in the history
add bridge address and asset IDs to genesis and check during execution
  • Loading branch information
noot authored Apr 3, 2024
2 parents d05e3b2 + a25ffda commit 744a32e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
4 changes: 3 additions & 1 deletion genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"astriaOverrideGenesisExtraData": true,
"astriaSequencerInitialHeight": 2,
"astriaCelestiaInitialHeight": 2,
"astriaCelestiaHeightVariance": 10
"astriaCelestiaHeightVariance": 10,
"astriaBridgeAddresses": [],
"astriaBridgeAllowedAssetDenom": "nria"
},
"difficulty": "10000000",
"gasLimit": "8000000",
Expand Down
44 changes: 38 additions & 6 deletions grpc/execution/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package execution

import (
"bytes"
"context"
"crypto/sha256"
"errors"
Expand Down Expand Up @@ -39,11 +40,14 @@ type ExecutionServiceServerV1Alpha2 struct {
eth *eth.Ethereum
bc *core.BlockChain

commitementUpdateLock sync.Mutex // Lock for the forkChoiceUpdated method
blockExecutionLock sync.Mutex // Lock for the NewPayload method
commitmentUpdateLock sync.Mutex // Lock for the forkChoiceUpdated method
blockExecutionLock sync.Mutex // Lock for the NewPayload method

genesisInfoCalled bool
getCommitmentStateCalled bool

bridgeAddresses map[string]struct{}
bridgeAllowedAssetID [32]byte
}

var (
Expand Down Expand Up @@ -87,13 +91,30 @@ func NewExecutionServiceServerV1Alpha2(eth *eth.Ethereum) (*ExecutionServiceServ
return nil, errors.New("celestia height variance not set")
}

if bc.Config().AstriaBridgeAddresses == nil {
log.Warn("bridge addresses not set")
}

if bc.Config().AstriaBridgeAllowedAssetDenom == "" && bc.Config().AstriaBridgeAddresses != nil {
return nil, errors.New("bridge allowed asset denom not set")
}

bridgeAddresses := make(map[string]struct{})
for _, addr := range bc.Config().AstriaBridgeAddresses {
bridgeAddresses[string(addr)] = struct{}{}
}

bridgeAllowedAssetID := sha256.Sum256([]byte(bc.Config().AstriaBridgeAllowedAssetDenom))

if merger := eth.Merger(); !merger.PoSFinalized() {
merger.FinalizePoS()
}

return &ExecutionServiceServerV1Alpha2{
eth: eth,
bc: bc,
eth: eth,
bc: bc,
bridgeAddresses: bridgeAddresses,
bridgeAllowedAssetID: bridgeAllowedAssetID,
}, nil
}

Expand Down Expand Up @@ -192,6 +213,17 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *
txsToProcess := types.Transactions{}
for _, tx := range req.Transactions {
if deposit := tx.GetDeposit(); deposit != nil {
bridgeAddress := string(deposit.BridgeAddress)
if _, ok := s.bridgeAddresses[bridgeAddress]; !ok {
log.Debug("ignoring deposit tx from unknown bridge", "bridgeAddress", bridgeAddress)
continue
}

if !bytes.Equal(deposit.AssetId, s.bridgeAllowedAssetID[:]) {
log.Debug("ignoring deposit tx with disallowed asset ID", "assetID", deposit.AssetId)
continue
}

address := common.HexToAddress(deposit.DestinationChainAddress)
txdata := types.DepositTx{
From: address,
Expand Down Expand Up @@ -295,8 +327,8 @@ func (s *ExecutionServiceServerV1Alpha2) UpdateCommitmentState(ctx context.Conte
commitmentUpdateStart := time.Now()
defer commitmentStateUpdateTimer.UpdateSince(commitmentUpdateStart)

s.commitementUpdateLock.Lock()
defer s.commitementUpdateLock.Unlock()
s.commitmentUpdateLock.Lock()
defer s.commitmentUpdateLock.Unlock()

if !s.syncMethodsCalled() {
return nil, status.Error(codes.PermissionDenied, "Cannot update commitment state until GetGenesisInfo && GetCommitmentState methods are called")
Expand Down
16 changes: 10 additions & 6 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,14 @@ type ChainConfig struct {
IsDevMode bool `json:"isDev,omitempty"`

// Astria Specific Configuration
AstriaOverrideGenesisExtraData bool `json:"astriaOverrideGenesisExtraData,omitempty"`
AstriaExtraDataOverride hexutil.Bytes `json:"astriaExtraDataOverride,omitempty"`
AstriaRollupName string `json:"astriaRollupName,omitempty"`
AstriaSequencerInitialHeight uint32 `json:"astriaSequencerInitialHeight"`
AstriaCelestiaInitialHeight uint32 `json:"astriaCelestiaInitialHeight"`
AstriaCelestiaHeightVariance uint32 `json:"astriaCelestiaHeightVariance,omitempty"`
AstriaOverrideGenesisExtraData bool `json:"astriaOverrideGenesisExtraData,omitempty"`
AstriaExtraDataOverride hexutil.Bytes `json:"astriaExtraDataOverride,omitempty"`
AstriaRollupName string `json:"astriaRollupName,omitempty"`
AstriaSequencerInitialHeight uint32 `json:"astriaSequencerInitialHeight"`
AstriaCelestiaInitialHeight uint32 `json:"astriaCelestiaInitialHeight"`
AstriaCelestiaHeightVariance uint32 `json:"astriaCelestiaHeightVariance,omitempty"`
AstriaBridgeAddresses []hexutil.Bytes `json:"astriaBridgeAddresses,omitempty"`
AstriaBridgeAllowedAssetDenom string `json:"astriaBridgeAllowedAssetDenom,omitempty"`
}

func (c *ChainConfig) AstriaExtraData() []byte {
Expand All @@ -356,6 +358,8 @@ func (c *ChainConfig) AstriaExtraData() []byte {
c.AstriaSequencerInitialHeight,
c.AstriaCelestiaInitialHeight,
c.AstriaCelestiaHeightVariance,
c.AstriaBridgeAddresses,
c.AstriaBridgeAllowedAssetDenom,
})
if uint64(len(extra)) > MaximumExtraDataSize {
log.Warn("Miner extra data exceed limit", "extra", hexutil.Bytes(extra), "limit", MaximumExtraDataSize)
Expand Down

0 comments on commit 744a32e

Please sign in to comment.