Skip to content

Commit

Permalink
review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
joroshiba committed Apr 26, 2024
1 parent 6b7c210 commit 0108d0b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"assetPrecision": 9
}
],
"AstriaFeeCollectors": {
"astriaFeeCollectors": {
"0xaC21B97d35Bf75A7dAb16f35b111a50e78A72F30": 1
}
},
Expand Down
22 changes: 15 additions & 7 deletions grpc/execution/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ type ExecutionServiceServerV1Alpha2 struct {
genesisInfoCalled bool
getCommitmentStateCalled bool

// astria bridge addess to config for that bridge account
bridgeAddresses map[string]*params.AstriaBridgeAddressConfig
// a set of allowed asset IDs structs are left empty
bridgeAllowedAssetIDs map[[32]byte]struct{}
// Map of the height to start using the fee collector to their address
feeRecipients map[uint32]*common.Address
nextFeeRecipient *common.Address
nextFeeRecipient common.Address // Fee recipient for the next block
}

var (
Expand Down Expand Up @@ -105,19 +108,21 @@ func NewExecutionServiceServerV1Alpha2(eth *eth.Ethereum) (*ExecutionServiceServ
return nil, fmt.Errorf("invalid bridge address config: %w", err)
}

if cfg.Erc20Asset != nil && nativeBridgeSeen {
return nil, errors.New("only one native bridge address is allowed")
}
if cfg.Erc20Asset != nil && !nativeBridgeSeen {
nativeBridgeSeen = true
} else if cfg.Erc20Asset != nil && nativeBridgeSeen {
return nil, errors.New("only one native bridge address is allowed")
}

bridgeAddresses[string(cfg.BridgeAddress)] = &cfg
assetID := sha256.Sum256([]byte(cfg.AssetDenom))
bridgeAllowedAssetIDs[assetID] = struct{}{}
}
}

feeRecipient := make(map[uint32]*common.Address)
nextFeeRecipient := &common.Address{}
nextFeeRecipient := common.Address{}
if bc.Config().AstriaFeeCollectors == nil {
log.Warn("fee asset collectors not set, assets will be burned")
} else {
Expand All @@ -127,7 +132,7 @@ func NewExecutionServiceServerV1Alpha2(eth *eth.Ethereum) (*ExecutionServiceServ
feeRecipient[height] = &collector
if height <= nextBlock && height > maxHeightCollectorMatch {
maxHeightCollectorMatch = height
nextFeeRecipient = &collector
nextFeeRecipient = collector
}
}
}
Expand Down Expand Up @@ -248,6 +253,9 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *
continue
}

if len(deposit.AssetId) != 32 {
log.Debug("ignoring deposit tx with invalid asset ID", "assetID", deposit.AssetId)
}
assetID := [32]byte{}
copy(assetID[:], deposit.AssetId[:32])
if _, ok := s.bridgeAllowedAssetIDs[assetID]; !ok {
Expand Down Expand Up @@ -296,7 +304,7 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *
Parent: prevHeadHash,
Timestamp: uint64(req.GetTimestamp().GetSeconds()),
Random: common.Hash{},
FeeRecipient: *s.nextFeeRecipient,
FeeRecipient: s.nextFeeRecipient,
}
payload, err := s.eth.Miner().BuildPayload(payloadAttributes)
if err != nil {
Expand Down Expand Up @@ -330,7 +338,7 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *
}

if next, ok := s.feeRecipients[res.Number+1]; ok {
s.nextFeeRecipient = next
s.nextFeeRecipient = *next
}

log.Info("ExecuteBlock completed", "request", req, "response", res)
Expand Down
3 changes: 0 additions & 3 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,9 +932,6 @@ func (abc *AstriaBridgeAddressConfig) Validate() error {
if abc.StartHeight == 0 {
return fmt.Errorf("start height must be greater than 0")
}
if abc.AssetPrecision == 0 {
return fmt.Errorf("asset precision must be greater than 0")
}
if abc.AssetDenom == "" {
return fmt.Errorf("asset denom must be set")
}
Expand Down

0 comments on commit 0108d0b

Please sign in to comment.