Skip to content

Commit

Permalink
wip: receiving block hash log
Browse files Browse the repository at this point in the history
  • Loading branch information
cam-schultz committed Sep 29, 2023
1 parent 4e602dc commit 02ee06b
Show file tree
Hide file tree
Showing 8 changed files with 668 additions and 262 deletions.
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ func (s *SourceSubnet) Validate() error {
return fmt.Errorf("invalid message contract address in EVM source subnet: %s", messageContractAddress)
}
}
case EVM_BLOCKHASH:
// No additional validation required
// TODONOW: we shouldn't require an address as the key for block hash publisher
default:
return fmt.Errorf("unsupported VM type for source subnet: %v", s.VM)
}
Expand Down
2 changes: 1 addition & 1 deletion main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func runRelayer(logger logging.Logger,
select {
case txLog := <-subscriber.Logs():
logger.Info(
"Handling Teleporter submit message log.",
"Handling message log.",
zap.String("txId", hex.EncodeToString(txLog.SourceTxID)),
zap.String("originChainId", sourceSubnetInfo.ChainID),
zap.String("destinationChainId", txLog.DestinationChainID.String()),
Expand Down
5 changes: 4 additions & 1 deletion messages/block_hash_publisher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ func (c *Config) Validate() error {
for i, destinationInfo := range c.DestinationChains {
// Check if the chainID is valid
if _, err := ids.FromString(destinationInfo.ChainID); err != nil {
return errors.Wrap(err, fmt.Sprintf("invalid subnetID in block hash publisher configuration. Provided ID: %s", destinationInfo.ChainID))
return errors.Wrap(err, fmt.Sprintf("invalid chainID in block hash publisher configuration. Provided ID: %s", destinationInfo.ChainID))
}

// Check if the address is valid
addr := destinationInfo.Address
if addr == "" {
return errors.New("empty address in block hash publisher configuration")
}
if strings.HasPrefix(addr, "0x") {
addr = addr[2:]
}
Expand Down
29 changes: 27 additions & 2 deletions messages/block_hash_publisher/message_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

const (
publishBlockHashGasLimit = 100000 // TODONOW: set the correct gas limit
publishBlockHashGasLimit = 1000000 // TODONOW: set the correct gas limit
)

type destinationSenderInfo struct {
Expand Down Expand Up @@ -45,7 +45,7 @@ func NewMessageManager(
messageProtocolConfig config.MessageProtocolConfig,
destinationClients map[ids.ID]vms.DestinationClient,
) (*messageManager, error) {
// Marshal the map and unmarshal into the Teleporter config
// Marshal the map and unmarshal into the Block Hash Publisher config
data, err := json.Marshal(messageProtocolConfig.Settings)
if err != nil {
logger.Error("Failed to marshal Block Hash Publisher config")
Expand All @@ -64,6 +64,7 @@ func NewMessageManager(
)
return nil, err
}
logger.Info("DEBUG CONFIG", zap.String("config", fmt.Sprintf("%#v", messageConfig)))

destinations := make(map[ids.ID]*destinationSenderInfo)
for _, destination := range messageConfig.DestinationChains {
Expand All @@ -78,9 +79,12 @@ func NewMessageManager(
destinations[destinationID] = &destinationSenderInfo{
useTimeInterval: destination.useTimeInterval,
timeIntervalSeconds: uint64(destination.timeIntervalSeconds),
blockInterval: uint64(destination.blockInterval),
address: common.HexToAddress(destination.Address),
client: destinationClients[destinationID],
}
logger.Info("DEBUG DESTINATIONS", zap.String("address", destinations[destinationID].address.String()))

}

return &messageManager{
Expand All @@ -93,6 +97,15 @@ func NewMessageManager(
func (m *messageManager) ShouldSendMessage(warpMessageInfo *vmtypes.WarpMessageInfo, destinationChainID ids.ID) (bool, error) {
destination, ok := m.destinations[destinationChainID]
if !ok {
var destinationIDs []string
for id := range m.destinations {
destinationIDs = append(destinationIDs, id.String())
}
m.logger.Info(
"DEBUG",
zap.String("destinationChainID", destinationChainID.String()),
zap.String("configuredDestinations", fmt.Sprintf("%#v", destinationIDs)),
)
return false, fmt.Errorf("relayer not configured to deliver to destination. destinationChainID=%s", destinationChainID)
}
if destination.useTimeInterval {
Expand All @@ -103,12 +116,24 @@ func (m *messageManager) ShouldSendMessage(warpMessageInfo *vmtypes.WarpMessageI
} else {
interval := destination.blockInterval
if warpMessageInfo.BlockNumber-destination.lastBlock < uint64(interval) {
m.logger.Info(
"DEBUG",
zap.String("decision", "Not sending"),
zap.Int("blockNum", int(warpMessageInfo.BlockNumber)),
zap.Int("lastBlockNum", int(destination.lastBlock)),
)
return false, nil
}
}
// Set the last approved block/time here. We don't set the last sent block/time until the message is actually sent
destination.lastApprovedBlock = warpMessageInfo.BlockNumber
destination.lastApprovedTime = warpMessageInfo.BlockTimestamp
m.logger.Info(
"DEBUG",
zap.String("decision", "Sending"),
zap.Int("blockNum", int(warpMessageInfo.BlockNumber)),
zap.Int("lastBlockNum", int(destination.lastBlock)),
)
return true, nil
}

Expand Down
1 change: 1 addition & 0 deletions tests/BlockHashReceiverByteCode.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x608060405234801561001057600080fd5b50600160008190558055610280806100296000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806330b525591461003b578063b771b3bc14610050575b600080fd5b61004e61004936600461018f565b61007a565b005b61005e6005600160991b0181565b6040516001600160a01b03909116815260200160405180910390f35b600180541461009c5760405163a815ca6b60e01b815260040160405180910390fd5b600260015560405163ce7f592960e01b815263ffffffff8316600482015260009081906005600160991b019063ce7f592990602401606060405180830381865afa1580156100ee573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061011291906101c4565b9150915080610134576040516339ecf43d60e21b815260040160405180910390fd5b815183146101555760405163e23ef14d60e01b815260040160405180910390fd5b602082015182516040517f7770e5f72465e9b05c8076c3f2eac70898abe6a84f0259307d127c13e2a1a4e490600090a35050600180555050565b600080604083850312156101a257600080fd5b823563ffffffff811681146101b657600080fd5b946020939093013593505050565b60008082840360608112156101d857600080fd5b60408112156101e657600080fd5b506040516040810181811067ffffffffffffffff8211171561021857634e487b7160e01b600052604160045260246000fd5b60409081528451825260208086015190830152840151909250801515811461023f57600080fd5b80915050925092905056fea264697066735822122035befb02f079d9bed5ae8edf23154d8ee3b487f193f6962a513df22f76fd6b6464736f6c63430008120033
Loading

0 comments on commit 02ee06b

Please sign in to comment.