From c46fc415d862b0fb64cfa0ef3a0473348feb6282 Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Mon, 5 Aug 2024 14:12:28 +0000 Subject: [PATCH 01/30] go.mod: use latest subnet-evm commit --- go.mod | 6 +++--- go.sum | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 6fc2fe79..f2dd3340 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,8 @@ module github.com/ava-labs/awm-relayer go 1.21.12 require ( - github.com/ava-labs/avalanchego v1.11.10-0.20240718133512-d9ddf0a774e1 - github.com/ava-labs/coreth v0.13.6-rc.1.0.20240718130554-0110293d1f4b - github.com/ava-labs/subnet-evm v0.6.8-status-removal.0.20240718155830-1d577b6a5e0b + github.com/ava-labs/avalanchego v1.11.11-0.20240729205337-a0f7e422bb84 + github.com/ava-labs/subnet-evm v0.6.9-0.20240802175433-caf34ea35fb4 github.com/ava-labs/teleporter v1.0.3 github.com/aws/aws-sdk-go-v2 v1.30.3 github.com/aws/aws-sdk-go-v2/config v1.27.9 @@ -26,6 +25,7 @@ require ( ) require ( + github.com/ava-labs/coreth v0.13.7 // indirect github.com/aws/aws-sdk-go-v2/credentials v1.17.9 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.0 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.15 // indirect diff --git a/go.sum b/go.sum index 9669380c..81ecc1af 100644 --- a/go.sum +++ b/go.sum @@ -58,12 +58,12 @@ github.com/alexliesenfeld/health v0.8.0/go.mod h1:TfNP0f+9WQVWMQRzvMUjlws4ceXKEL github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/ava-labs/avalanchego v1.11.10-0.20240718133512-d9ddf0a774e1 h1:RhyF0H8Rknz4sdYU3+Y8o6I4xodktqf/YzyfDZWKowg= -github.com/ava-labs/avalanchego v1.11.10-0.20240718133512-d9ddf0a774e1/go.mod h1:a+A78rkfjmTRU5k4BksGcAO8tleeyLEKjXOzBbwwAXU= -github.com/ava-labs/coreth v0.13.6-rc.1.0.20240718130554-0110293d1f4b h1:XUc8KVA76s08ZdN92j2IMlKr3g9OGVPf6FlAxea42wI= -github.com/ava-labs/coreth v0.13.6-rc.1.0.20240718130554-0110293d1f4b/go.mod h1:EXQ/+Uk64XTBdMvgmapzy56dZ8xEkbVSgNMpSLkTKos= -github.com/ava-labs/subnet-evm v0.6.8-status-removal.0.20240718155830-1d577b6a5e0b h1:qGNyH3O3VanpbgFW6DbxCAV/qF6QUDs2Ckul6wuEhmg= -github.com/ava-labs/subnet-evm v0.6.8-status-removal.0.20240718155830-1d577b6a5e0b/go.mod h1:Dw/PykU2GR/FPl3Psoi9Pp6HL1qEl8Jm3QcBsBKobBQ= +github.com/ava-labs/avalanchego v1.11.11-0.20240729205337-a0f7e422bb84 h1:AmPZLlnVREbJ/viK/hDTIVn1bqX8QTB2CFtrBxHwnsw= +github.com/ava-labs/avalanchego v1.11.11-0.20240729205337-a0f7e422bb84/go.mod h1:POgZPryqe80OeHCDNrXrPOKoFre736iFuMgmUBeKaLc= +github.com/ava-labs/coreth v0.13.7 h1:k8T9u/ROifl8f7oXjHRc1KvSISRl9txvy7gGVmHEz6g= +github.com/ava-labs/coreth v0.13.7/go.mod h1:tXDujonxXFOF6oK5HS2EmgtSXJK3Gy6RpZxb5WzR9rM= +github.com/ava-labs/subnet-evm v0.6.9-0.20240802175433-caf34ea35fb4 h1:hD67mjzCx9yb7JNHHEb/g50BHx2NTdceEx6f72kMUuc= +github.com/ava-labs/subnet-evm v0.6.9-0.20240802175433-caf34ea35fb4/go.mod h1:BryiYmD6HWmugkSUpDdj/KyMi7ou5pJzPRNPMbMgpbA= github.com/ava-labs/teleporter v1.0.3 h1:5Kwso1yk5dtuIg7356MF+cJFRFge8nvun/JK0MDAUAM= github.com/ava-labs/teleporter v1.0.3/go.mod h1:h8wp8x7531OLeyQUzC2M20S6AVXSuj598Hmo8QSUVOM= github.com/aws/aws-sdk-go-v2 v1.30.3 h1:jUeBtG0Ih+ZIFH0F4UkmL9w3cSpaMv9tYYDbzILP8dY= From 650c987384e1c2cff7a730f81dd9862afb24a2c8 Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Mon, 5 Aug 2024 14:27:26 +0000 Subject: [PATCH 02/30] integrate w/ACP-118 protobuf SignatureRequest --- signature-aggregator/aggregator/aggregator.go | 23 ++++--------------- 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/signature-aggregator/aggregator/aggregator.go b/signature-aggregator/aggregator/aggregator.go index d481328b..9c01176c 100644 --- a/signature-aggregator/aggregator/aggregator.go +++ b/signature-aggregator/aggregator/aggregator.go @@ -16,17 +16,17 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/message" "github.com/ava-labs/avalanchego/proto/pb/p2p" + "github.com/ava-labs/avalanchego/proto/pb/sdk" "github.com/ava-labs/avalanchego/subnets" - "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/set" avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ava-labs/awm-relayer/peers" "github.com/ava-labs/awm-relayer/utils" - coreEthMsg "github.com/ava-labs/coreth/plugin/evm/message" msg "github.com/ava-labs/subnet-evm/plugin/evm/message" "go.uber.org/zap" + "google.golang.org/protobuf/proto" ) type blsSignatureBuf [bls.SignatureLen]byte @@ -40,9 +40,6 @@ const ( ) var ( - codec = msg.Codec - coreEthCodec = coreEthMsg.Codec - // Errors errNotEnoughSignatures = errors.New("failed to collect a threshold of signatures") errNotEnoughConnectedStake = errors.New("failed to connect to a threshold of stake") @@ -121,19 +118,9 @@ func (s *SignatureAggregator) AggregateSignaturesAppRequest( return nil, errNotEnoughConnectedStake } - // TODO: remove this special handling and replace with ACP-118 interface once available - var reqBytes []byte - if sourceSubnet == constants.PrimaryNetworkID { - req := coreEthMsg.MessageSignatureRequest{ - MessageID: unsignedMessage.ID(), - } - reqBytes, err = coreEthMsg.RequestToBytes(coreEthCodec, req) - } else { - req := msg.MessageSignatureRequest{ - MessageID: unsignedMessage.ID(), - } - reqBytes, err = msg.RequestToBytes(codec, req) - } + reqBytes, err := proto.Marshal( + &sdk.SignatureRequest{Message: unsignedMessage.Bytes()}, + ) if err != nil { msg := "Failed to marshal request bytes" s.logger.Error( From a9c77688aebc343e8f71b398a42656f78d3409c4 Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Mon, 5 Aug 2024 14:36:29 +0000 Subject: [PATCH 03/30] test relayer & aggregator: log debug by default --- tests/utils/utils.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/utils/utils.go b/tests/utils/utils.go index 270706ad..78927331 100644 --- a/tests/utils/utils.go +++ b/tests/utils/utils.go @@ -255,7 +255,7 @@ func CreateDefaultRelayerConfig( } return config.Config{ - LogLevel: logging.Info.LowerString(), + LogLevel: logging.Debug.LowerString(), PChainAPI: &config.APIConfig{ BaseURL: sourceSubnetsInfo[0].NodeURIs[0], }, @@ -287,7 +287,7 @@ func CreateDefaultSignatureAggregatorConfig( ) // Construct the config values for each subnet return signatureaggregatorcfg.Config{ - LogLevel: logging.Info.LowerString(), + LogLevel: logging.Debug.LowerString(), PChainAPI: &config.APIConfig{ BaseURL: sourceSubnetsInfo[0].NodeURIs[0], }, From 557262accb902b63364c1ce5e994f08071d45562 Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Tue, 6 Aug 2024 15:31:40 +0000 Subject: [PATCH 04/30] add justification, rename message to drop Unsigned addresses review comment https://github.com/ava-labs/awm-relayer/pull/408#discussion_r1704665402 --- relayer/application_relayer.go | 1 + signature-aggregator/aggregator/aggregator.go | 1 + signature-aggregator/api/api.go | 49 ++++++++++++++++--- tests/signature_aggregator_api.go | 2 +- 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/relayer/application_relayer.go b/relayer/application_relayer.go index 682f4772..8daecf58 100644 --- a/relayer/application_relayer.go +++ b/relayer/application_relayer.go @@ -209,6 +209,7 @@ func (r *ApplicationRelayer) ProcessMessage(handler messages.MessageHandler) (co // TODO: do we actually want to pass the pointer here or adapt the interface? signedMessage, err = r.signatureAggregator.AggregateSignaturesAppRequest( unsignedMessage, + make([]byte, 0), r.signingSubnetID, r.warpQuorum.QuorumNumerator, ) diff --git a/signature-aggregator/aggregator/aggregator.go b/signature-aggregator/aggregator/aggregator.go index 9c01176c..7077732e 100644 --- a/signature-aggregator/aggregator/aggregator.go +++ b/signature-aggregator/aggregator/aggregator.go @@ -72,6 +72,7 @@ func NewSignatureAggregator( func (s *SignatureAggregator) AggregateSignaturesAppRequest( unsignedMessage *avalancheWarp.UnsignedMessage, + justification []byte, inputSigningSubnet ids.ID, quorumPercentage uint64, ) (*avalancheWarp.Message, error) { diff --git a/signature-aggregator/api/api.go b/signature-aggregator/api/api.go index 0f48f23c..d5e4684a 100644 --- a/signature-aggregator/api/api.go +++ b/signature-aggregator/api/api.go @@ -25,8 +25,12 @@ const ( // Defines a request interface for signature aggregation for a raw unsigned message. // Currently a copy of the `ManualWarpMessageRequest` struct in relay_message.go type AggregateSignaturesByRawMsgRequest struct { - // Required. hex-encoded message, optionally prefixed with "0x". - UnsignedMessage string `json:"unsigned-message"` + // Required: either Message or Justification must be provided + + // hex-encoded message, optionally prefixed with "0x". + Message string `json:"message"` + // hex-encoded justification, optionally prefixed with "0x". + Justification string `json:"justification"` // Optional hex or cb58 encoded signing subnet ID. If omitted will default to the subnetID of the source BlockChain SigningSubnetID string `json:"signing-subnet-id"` // Optional. Integer from 0 to 100 representing the percentage of the quorum that is required to sign the message @@ -66,6 +70,15 @@ func writeJsonError( } } +func isEmptyOrZeroes(bytes []byte) bool { + for _, b := range bytes { + if b != 0 { + return false + } + } + return true +} + func signatureAggregationAPIHandler(logger logging.Logger, aggregator *aggregator.SignatureAggregator) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var req AggregateSignaturesByRawMsgRequest @@ -78,25 +91,48 @@ func signatureAggregationAPIHandler(logger logging.Logger, aggregator *aggregato } var decodedMessage []byte decodedMessage, err = hex.DecodeString( - strings.TrimPrefix(req.UnsignedMessage, "0x"), + strings.TrimPrefix(req.Message, "0x"), ) if err != nil { msg := "Could not decode message" logger.Warn( msg, - zap.String("msg", req.UnsignedMessage), + zap.String("msg", req.Message), zap.Error(err), ) writeJsonError(logger, w, msg) return } - unsignedMessage, err := types.UnpackWarpMessage(decodedMessage) + message, err := types.UnpackWarpMessage(decodedMessage) if err != nil { msg := "Error unpacking warp message" logger.Warn(msg, zap.Error(err)) writeJsonError(logger, w, msg) return } + + justification, err := hex.DecodeString( + strings.TrimPrefix(req.Justification, "0x"), + ) + if err != nil { + msg := "Could not decode justification" + logger.Warn( + msg, + zap.String("justification", req.Justification), + zap.Error(err), + ) + writeJsonError(logger, w, msg) + return + } + + if isEmptyOrZeroes(message.Bytes()) || isEmptyOrZeroes(justification) { + writeJsonError( + logger, + w, + "Must provide either message or justification", + ) + } + quorumNum := req.QuorumNum if quorumNum == 0 { quorumNum = defaultQuorumNum @@ -123,7 +159,8 @@ func signatureAggregationAPIHandler(logger logging.Logger, aggregator *aggregato } signedMessage, err := aggregator.AggregateSignaturesAppRequest( - unsignedMessage, + message, + justification, signingSubnetID, quorumNum, ) diff --git a/tests/signature_aggregator_api.go b/tests/signature_aggregator_api.go index 205e3d1d..cd8ed9a9 100644 --- a/tests/signature_aggregator_api.go +++ b/tests/signature_aggregator_api.go @@ -56,7 +56,7 @@ func SignatureAggregatorAPI(network interfaces.LocalNetwork) { time.Sleep(5 * time.Second) reqBody := api.AggregateSignaturesByRawMsgRequest{ - UnsignedMessage: "0x" + hex.EncodeToString(warpMessage.Bytes()), + Message: "0x" + hex.EncodeToString(warpMessage.Bytes()), } client := http.Client{ From f399cffc649a29210a69a27aebb2a0e1203bcb9a Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Wed, 7 Aug 2024 15:25:33 +0000 Subject: [PATCH 05/30] re-pin dependencies --- go.mod | 16 +++++------ go.sum | 32 ++++++++++----------- messages/teleporter/message_handler.go | 5 ++-- messages/teleporter/message_handler_test.go | 2 +- scripts/versions.sh | 6 ++-- tests/utils/utils.go | 3 +- 6 files changed, 34 insertions(+), 30 deletions(-) diff --git a/go.mod b/go.mod index 6a8ce95a..82d9ca2c 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,8 @@ go 1.21.12 require ( github.com/ava-labs/avalanchego v1.11.11-0.20240729205337-a0f7e422bb84 - github.com/ava-labs/subnet-evm v0.6.9-0.20240802175433-caf34ea35fb4 - github.com/ava-labs/teleporter v1.0.3 + github.com/ava-labs/subnet-evm v0.6.8-acp-118-handlers + github.com/ava-labs/teleporter v1.0.5-0.20240807150146-1c7df1ab5033 github.com/aws/aws-sdk-go-v2 v1.30.3 github.com/aws/aws-sdk-go-v2/config v1.27.9 github.com/aws/aws-sdk-go-v2/service/kms v1.35.3 @@ -93,7 +93,7 @@ require ( github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect go.opentelemetry.io/otel/metric v1.22.0 // indirect golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect - golang.org/x/tools v0.23.0 // indirect + golang.org/x/tools v0.24.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect gopkg.in/ini.v1 v1.67.0 // indirect @@ -152,12 +152,12 @@ require ( go.opentelemetry.io/proto/otlp v1.0.0 // indirect go.uber.org/atomic v1.11.0 go.uber.org/multierr v1.11.0 // indirect - golang.org/x/crypto v0.25.0 // indirect - golang.org/x/net v0.27.0 // indirect + golang.org/x/crypto v0.26.0 // indirect + golang.org/x/net v0.28.0 // indirect golang.org/x/sync v0.8.0 - golang.org/x/sys v0.22.0 // indirect - golang.org/x/term v0.22.0 // indirect - golang.org/x/text v0.16.0 // indirect + golang.org/x/sys v0.23.0 // indirect + golang.org/x/term v0.23.0 // indirect + golang.org/x/text v0.17.0 // indirect golang.org/x/time v0.3.0 // indirect gonum.org/v1/gonum v0.11.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect diff --git a/go.sum b/go.sum index 938210b6..bfbee1e0 100644 --- a/go.sum +++ b/go.sum @@ -62,10 +62,10 @@ github.com/ava-labs/avalanchego v1.11.11-0.20240729205337-a0f7e422bb84 h1:AmPZLl github.com/ava-labs/avalanchego v1.11.11-0.20240729205337-a0f7e422bb84/go.mod h1:POgZPryqe80OeHCDNrXrPOKoFre736iFuMgmUBeKaLc= github.com/ava-labs/coreth v0.13.7 h1:k8T9u/ROifl8f7oXjHRc1KvSISRl9txvy7gGVmHEz6g= github.com/ava-labs/coreth v0.13.7/go.mod h1:tXDujonxXFOF6oK5HS2EmgtSXJK3Gy6RpZxb5WzR9rM= -github.com/ava-labs/subnet-evm v0.6.9-0.20240802175433-caf34ea35fb4 h1:hD67mjzCx9yb7JNHHEb/g50BHx2NTdceEx6f72kMUuc= -github.com/ava-labs/subnet-evm v0.6.9-0.20240802175433-caf34ea35fb4/go.mod h1:BryiYmD6HWmugkSUpDdj/KyMi7ou5pJzPRNPMbMgpbA= -github.com/ava-labs/teleporter v1.0.3 h1:5Kwso1yk5dtuIg7356MF+cJFRFge8nvun/JK0MDAUAM= -github.com/ava-labs/teleporter v1.0.3/go.mod h1:h8wp8x7531OLeyQUzC2M20S6AVXSuj598Hmo8QSUVOM= +github.com/ava-labs/subnet-evm v0.6.8-acp-118-handlers h1:2UVHP9TDh3eS/CuD/XzMy2+3ruu/U2ZUny1eqn4bNB4= +github.com/ava-labs/subnet-evm v0.6.8-acp-118-handlers/go.mod h1:BryiYmD6HWmugkSUpDdj/KyMi7ou5pJzPRNPMbMgpbA= +github.com/ava-labs/teleporter v1.0.5-0.20240807150146-1c7df1ab5033 h1:mqtcLphkixDnYY5h8eQlj058KiVpRJaQgGvuUZcAcXo= +github.com/ava-labs/teleporter v1.0.5-0.20240807150146-1c7df1ab5033/go.mod h1:xDSsLZTLQ68ZXs9tb00VNd4fODqHTs6AD3MX6cyQ00Y= github.com/aws/aws-sdk-go-v2 v1.30.3 h1:jUeBtG0Ih+ZIFH0F4UkmL9w3cSpaMv9tYYDbzILP8dY= github.com/aws/aws-sdk-go-v2 v1.30.3/go.mod h1:nIQjQVp5sfpQcTc9mPSr1B0PaWK5ByX9MOoDadSN4lc= github.com/aws/aws-sdk-go-v2/config v1.27.9 h1:gRx/NwpNEFSk+yQlgmk1bmxxvQ5TyJ76CWXs9XScTqg= @@ -672,8 +672,8 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= -golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -757,8 +757,8 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= -golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= +golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= +golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -847,12 +847,12 @@ golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= +golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= -golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= +golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU= +golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -863,8 +863,8 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -926,8 +926,8 @@ golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg= -golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI= +golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= +golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/messages/teleporter/message_handler.go b/messages/teleporter/message_handler.go index dd7d8b58..586292fd 100644 --- a/messages/teleporter/message_handler.go +++ b/messages/teleporter/message_handler.go @@ -388,7 +388,8 @@ func (f *factory) parseTeleporterMessage( ) return nil, err } - teleporterMessage, err := teleportermessenger.UnpackTeleporterMessage(addressedPayload.Payload) + teleporterMessage := teleportermessenger.TeleporterMessage{} + err = teleporterMessage.Unpack(addressedPayload.Payload) if err != nil { f.logger.Error( "Failed unpacking teleporter message.", @@ -397,7 +398,7 @@ func (f *factory) parseTeleporterMessage( return nil, err } - return teleporterMessage, nil + return &teleporterMessage, nil } // getTeleporterMessenger returns the Teleporter messenger instance for the destination chain. diff --git a/messages/teleporter/message_handler_test.go b/messages/teleporter/message_handler_test.go index 677735be..aa0b0c86 100644 --- a/messages/teleporter/message_handler_test.go +++ b/messages/teleporter/message_handler_test.go @@ -70,7 +70,7 @@ func init() { } func TestShouldSendMessage(t *testing.T) { - validMessageBytes, err := teleportermessenger.PackTeleporterMessage(validTeleporterMessage) + validMessageBytes, err := validTeleporterMessage.Pack() require.NoError(t, err) validAddressedCall, err := warpPayload.NewAddressedCall( diff --git a/scripts/versions.sh b/scripts/versions.sh index 4c00db33..468eaf8a 100755 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -17,12 +17,14 @@ function getDepVersion() { export GO_VERSION=${GO_VERSION:-$(getDepVersion go)} # Don't export them as they're used in the context of other calls -AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-$(getDepVersion github.com/ava-labs/avalanchego)} +# TODO: undo this hack once go.mod is referring to a tag rather than a commit +#AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-$(getDepVersion github.com/ava-labs/avalanchego)} +AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-a0f7e422bb8497186ebff434f12c4b957cec8d49} GINKGO_VERSION=${GINKGO_VERSION:-$(getDepVersion github.com/onsi/ginkgo/v2)} # TODO: undo this hack once go.mod is referring to a tag rather than a commit #SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-$(getDepVersion github.com/ava-labs/subnet-evm)} -SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-update-avago-teleporter} +SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-v0.6.8-acp-118-handlers} # Set golangci-lint version GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION:-'v1.55'} diff --git a/tests/utils/utils.go b/tests/utils/utils.go index 78927331..af770173 100644 --- a/tests/utils/utils.go +++ b/tests/utils/utils.go @@ -473,7 +473,8 @@ func RelayBasicMessage( // Check that the teleporter message is correct // We don't validate the entire message, since the message receipts // are populated by the Teleporter contract - receivedTeleporterMessage, err := teleportermessenger.UnpackTeleporterMessage(addressedPayload.Payload) + receivedTeleporterMessage := teleportermessenger.TeleporterMessage{} + err = receivedTeleporterMessage.Unpack(addressedPayload.Payload) Expect(err).Should(BeNil()) receivedMessageID, err := teleporterUtils.CalculateMessageID( From c771ca9b3724e2744e71ff2fb00c288639c98772 Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Wed, 7 Aug 2024 16:05:37 +0000 Subject: [PATCH 06/30] sync teleporter git submodule to go.mod version --- tests/contracts/lib/teleporter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/contracts/lib/teleporter b/tests/contracts/lib/teleporter index 8b7d7245..1c7df1ab 160000 --- a/tests/contracts/lib/teleporter +++ b/tests/contracts/lib/teleporter @@ -1 +1 @@ -Subproject commit 8b7d7245d6998f14a0655b86670c998ba5e5f964 +Subproject commit 1c7df1ab5033fc3b679729a2b0db8941a9ae3329 From fa60e039d4d5ee07328e2a5f0a88a515e41dbd9e Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Thu, 8 Aug 2024 10:54:52 -0400 Subject: [PATCH 07/30] version bumps, logging and handlerid packing hacks --- go.mod | 8 +++---- go.sum | 16 +++++++------- peers/external_handler.go | 3 +++ scripts/versions.sh | 2 +- signature-aggregator/aggregator/aggregator.go | 21 ++++++++++++------- tests/contracts/lib/teleporter | 2 +- 6 files changed, 31 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 82d9ca2c..4e3ef774 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/ava-labs/awm-relayer go 1.21.12 require ( - github.com/ava-labs/avalanchego v1.11.11-0.20240729205337-a0f7e422bb84 - github.com/ava-labs/subnet-evm v0.6.8-acp-118-handlers - github.com/ava-labs/teleporter v1.0.5-0.20240807150146-1c7df1ab5033 + github.com/ava-labs/avalanchego v1.11.11-0.20240808144601-8d602b350f59 + github.com/ava-labs/subnet-evm v0.6.9-0.20240806212213-c2da67db92f8 + github.com/ava-labs/teleporter v1.0.5-0.20240808145337-a3092c7f50ea github.com/aws/aws-sdk-go-v2 v1.30.3 github.com/aws/aws-sdk-go-v2/config v1.27.9 github.com/aws/aws-sdk-go-v2/service/kms v1.35.3 @@ -25,7 +25,7 @@ require ( ) require ( - github.com/ava-labs/coreth v0.13.7 // indirect + github.com/ava-labs/coreth v0.13.8-0.20240807212152-f7acfafec094 // indirect github.com/aws/aws-sdk-go-v2/credentials v1.17.9 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.0 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.15 // indirect diff --git a/go.sum b/go.sum index bfbee1e0..e4da3ab0 100644 --- a/go.sum +++ b/go.sum @@ -58,14 +58,14 @@ github.com/alexliesenfeld/health v0.8.0/go.mod h1:TfNP0f+9WQVWMQRzvMUjlws4ceXKEL github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/ava-labs/avalanchego v1.11.11-0.20240729205337-a0f7e422bb84 h1:AmPZLlnVREbJ/viK/hDTIVn1bqX8QTB2CFtrBxHwnsw= -github.com/ava-labs/avalanchego v1.11.11-0.20240729205337-a0f7e422bb84/go.mod h1:POgZPryqe80OeHCDNrXrPOKoFre736iFuMgmUBeKaLc= -github.com/ava-labs/coreth v0.13.7 h1:k8T9u/ROifl8f7oXjHRc1KvSISRl9txvy7gGVmHEz6g= -github.com/ava-labs/coreth v0.13.7/go.mod h1:tXDujonxXFOF6oK5HS2EmgtSXJK3Gy6RpZxb5WzR9rM= -github.com/ava-labs/subnet-evm v0.6.8-acp-118-handlers h1:2UVHP9TDh3eS/CuD/XzMy2+3ruu/U2ZUny1eqn4bNB4= -github.com/ava-labs/subnet-evm v0.6.8-acp-118-handlers/go.mod h1:BryiYmD6HWmugkSUpDdj/KyMi7ou5pJzPRNPMbMgpbA= -github.com/ava-labs/teleporter v1.0.5-0.20240807150146-1c7df1ab5033 h1:mqtcLphkixDnYY5h8eQlj058KiVpRJaQgGvuUZcAcXo= -github.com/ava-labs/teleporter v1.0.5-0.20240807150146-1c7df1ab5033/go.mod h1:xDSsLZTLQ68ZXs9tb00VNd4fODqHTs6AD3MX6cyQ00Y= +github.com/ava-labs/avalanchego v1.11.11-0.20240808144601-8d602b350f59 h1:Od3s9c4SMDfozvRfVFahPL8IhG8hiPSkJrRuT95XZa0= +github.com/ava-labs/avalanchego v1.11.11-0.20240808144601-8d602b350f59/go.mod h1:Sq26Wg2Yz0k0EzueGMamRzw4apv6wmNi7vPjxX4nNSk= +github.com/ava-labs/coreth v0.13.8-0.20240807212152-f7acfafec094 h1:e7TvIKDGzsMsKU3Y4HreRcK7f16EcEPUO04UwSCFtng= +github.com/ava-labs/coreth v0.13.8-0.20240807212152-f7acfafec094/go.mod h1:Ouul9dJouniUIJVX1gDqx8CrHyGvmwZkK28mrgKb/4I= +github.com/ava-labs/subnet-evm v0.6.9-0.20240806212213-c2da67db92f8 h1:7G7ABONT72tBC/FSTfKj2sNcqTCo47GKqGeYCtMI0hM= +github.com/ava-labs/subnet-evm v0.6.9-0.20240806212213-c2da67db92f8/go.mod h1:n5jDyKtXZsHxbb5xPOUwhVaKbMCU/oTNTnBjn8Nfau0= +github.com/ava-labs/teleporter v1.0.5-0.20240808145337-a3092c7f50ea h1:4O1KXIpxbxQMWueo9K0ZMvYFj7znb1qbBUnFP/CuMfw= +github.com/ava-labs/teleporter v1.0.5-0.20240808145337-a3092c7f50ea/go.mod h1:9f05xmaQ2IXn4D4jcuHQdyqyn8g+IIT+CaynQQqnI0M= github.com/aws/aws-sdk-go-v2 v1.30.3 h1:jUeBtG0Ih+ZIFH0F4UkmL9w3cSpaMv9tYYDbzILP8dY= github.com/aws/aws-sdk-go-v2 v1.30.3/go.mod h1:nIQjQVp5sfpQcTc9mPSr1B0PaWK5ByX9MOoDadSN4lc= github.com/aws/aws-sdk-go-v2/config v1.27.9 h1:gRx/NwpNEFSk+yQlgmk1bmxxvQ5TyJ76CWXs9XScTqg= diff --git a/peers/external_handler.go b/peers/external_handler.go index 063437bd..3d31bb67 100644 --- a/peers/external_handler.go +++ b/peers/external_handler.go @@ -88,6 +88,9 @@ func (h *RelayerExternalHandler) HandleInbound(_ context.Context, inboundMessage zap.Stringer("from", inboundMessage.NodeID()), ) if inboundMessage.Op() == message.AppResponseOp || inboundMessage.Op() == message.AppErrorOp { + if inboundMessage.Op() == message.AppErrorOp { + h.log.Debug("Received AppError message", zap.Stringer("message", inboundMessage.Message())) + } h.registerAppResponse(inboundMessage) } else { h.log.Debug("Ignoring message", zap.Stringer("op", inboundMessage.Op())) diff --git a/scripts/versions.sh b/scripts/versions.sh index 468eaf8a..62c43b29 100755 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -19,7 +19,7 @@ export GO_VERSION=${GO_VERSION:-$(getDepVersion go)} # Don't export them as they're used in the context of other calls # TODO: undo this hack once go.mod is referring to a tag rather than a commit #AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-$(getDepVersion github.com/ava-labs/avalanchego)} -AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-a0f7e422bb8497186ebff434f12c4b957cec8d49} +AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-8d602b350f599fcaa67882dcbed5086feb5579a1} GINKGO_VERSION=${GINKGO_VERSION:-$(getDepVersion github.com/onsi/ginkgo/v2)} # TODO: undo this hack once go.mod is referring to a tag rather than a commit diff --git a/signature-aggregator/aggregator/aggregator.go b/signature-aggregator/aggregator/aggregator.go index bfed875f..177d7736 100644 --- a/signature-aggregator/aggregator/aggregator.go +++ b/signature-aggregator/aggregator/aggregator.go @@ -5,6 +5,7 @@ package aggregator import ( "bytes" + "encoding/binary" "errors" "fmt" "math/big" @@ -15,6 +16,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/message" + networkP2P "github.com/ava-labs/avalanchego/network/p2p" "github.com/ava-labs/avalanchego/proto/pb/p2p" "github.com/ava-labs/avalanchego/proto/pb/sdk" "github.com/ava-labs/avalanchego/subnets" @@ -24,7 +26,6 @@ import ( avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ava-labs/awm-relayer/peers" "github.com/ava-labs/awm-relayer/utils" - msg "github.com/ava-labs/subnet-evm/plugin/evm/message" "go.uber.org/zap" "google.golang.org/protobuf/proto" ) @@ -119,10 +120,14 @@ func (s *SignatureAggregator) CreateSignedMessage( ) return nil, errNotEnoughConnectedStake } - - reqBytes, err := proto.Marshal( + numBytes := make([]byte, 8) + // Convert the uint64 to a byte slice using big-endian encoding + binary.BigEndian.PutUint64(numBytes, networkP2P.SignatureRequestHandlerID) + reqBytes := networkP2P.ProtocolPrefix(networkP2P.SignatureRequestHandlerID) + messageBytes, err := proto.Marshal( &sdk.SignatureRequest{Message: unsignedMessage.Bytes()}, ) + reqBytes = append(reqBytes, messageBytes...) if err != nil { msg := "Failed to marshal request bytes" s.logger.Error( @@ -426,8 +431,9 @@ func (s *SignatureAggregator) isValidSignatureResponse( return blsSignatureBuf{}, false } - var sigResponse msg.SignatureResponse - if _, err := msg.Codec.Unmarshal(appResponse.AppBytes, &sigResponse); err != nil { + sigResponse := sdk.SignatureResponse{} + err := proto.Unmarshal(appResponse.AppBytes, &sigResponse) + if err != nil { s.logger.Error( "Error unmarshaling signature response", zap.Error(err), @@ -459,8 +465,9 @@ func (s *SignatureAggregator) isValidSignatureResponse( ) return blsSignatureBuf{}, false } - - return signature, true + blsSig := blsSignatureBuf{} + copy(blsSig[:], signature[:]) + return blsSig, true } // aggregateSignatures constructs a BLS aggregate signature from the collected validator signatures. Also diff --git a/tests/contracts/lib/teleporter b/tests/contracts/lib/teleporter index 1c7df1ab..8b7d7245 160000 --- a/tests/contracts/lib/teleporter +++ b/tests/contracts/lib/teleporter @@ -1 +1 @@ -Subproject commit 1c7df1ab5033fc3b679729a2b0db8941a9ae3329 +Subproject commit 8b7d7245d6998f14a0655b86670c998ba5e5f964 From 0108081ac47f9c524ceca5dd95d353c458f2001b Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Thu, 8 Aug 2024 12:07:04 -0400 Subject: [PATCH 08/30] Update signature-aggregator/README.md Co-authored-by: cam-schultz <78878559+cam-schultz@users.noreply.github.com> Signed-off-by: Ian Suvak --- signature-aggregator/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/signature-aggregator/README.md b/signature-aggregator/README.md index b0befa47..eeabf5b8 100644 --- a/signature-aggregator/README.md +++ b/signature-aggregator/README.md @@ -35,7 +35,7 @@ The only exposed endpoint is `/aggregate-signatures` expecting `application/jso ## Sample workflow If you want to manually test a locally running service pointed to the Fuji testnet you can do so with the following steps. -Note that this might fail for older messages if there has been enough validator churn, and less then threhold weight of stake of validators have seen the message when it originated. In this case try picking a more recent message. +Note that this might fail for older messages if there has been enough validator churn, and less then the threshold weight of stake of validators have seen the message when it originated. In this case try picking a more recent message. The basic request consists of sending just the `data` field containing the hex-encoded bytes of the full unsigned Warp message that the validators would be willing to sign. Here are the steps to obtain a sample valid unsigned Warp message bytes from the Fuji network. From cf689e53b517cb1550d37e792917d584f974060b Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Thu, 8 Aug 2024 13:24:24 -0400 Subject: [PATCH 09/30] Update signature-aggregator/README.md Co-authored-by: Geoff Stuart Signed-off-by: Ian Suvak --- signature-aggregator/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/signature-aggregator/README.md b/signature-aggregator/README.md index eeabf5b8..34357760 100644 --- a/signature-aggregator/README.md +++ b/signature-aggregator/README.md @@ -27,7 +27,7 @@ The only exposed endpoint is `/aggregate-signatures` expecting `application/jso { "message": "", // (string) hex-encoded unsigned message bytes to be signed "justification": "", // (string) hex-encoded bytes to supply to the validators as justification - . "signing-subnet-id": "", // (string) hex or cb58 encoded signing subnet ID. Defaults to source blockchain's subnet from data if omitted. + "signing-subnet-id": "", // (string) hex or cb58 encoded signing subnet ID. Defaults to source blockchain's subnet from data if omitted. "quorum-percentage": 67 // (int) quorum percentage required to sign the message. Defaults to 67 if omitted } ``` From b186d1c8271782a99b8fd14336763cb3448f1eb5 Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Thu, 8 Aug 2024 15:03:51 -0400 Subject: [PATCH 10/30] address review feedback --- signature-aggregator/api/api.go | 6 +++--- signature-aggregator/main/main.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/signature-aggregator/api/api.go b/signature-aggregator/api/api.go index fd66f33f..810ab954 100644 --- a/signature-aggregator/api/api.go +++ b/signature-aggregator/api/api.go @@ -18,8 +18,8 @@ import ( ) const ( - APIPath = "/aggregate-signatures" - QuorumPercentage = 67 + APIPath = "/aggregate-signatures" + DefaultQuorumPercentage = 67 ) // Defines a request interface for signature aggregation for a raw unsigned message. @@ -133,7 +133,7 @@ func signatureAggregationAPIHandler(logger logging.Logger, aggregator *aggregato quorumPercentage := req.QuorumPercentage if quorumPercentage == 0 { - quorumPercentage = QuorumPercentage + quorumPercentage = DefaultQuorumPercentage } else if req.QuorumPercentage > 100 { msg := "Invalid quorum number" logger.Warn(msg, zap.Uint64("quorum-num", req.QuorumPercentage)) diff --git a/signature-aggregator/main/main.go b/signature-aggregator/main/main.go index e942eac5..7bce0445 100644 --- a/signature-aggregator/main/main.go +++ b/signature-aggregator/main/main.go @@ -26,8 +26,8 @@ var version = "v0.0.0-dev" func main() { fs := config.BuildFlagSet() if err := fs.Parse(os.Args[1:]); err != nil { - fmt.Println("Failed to parse flags: %w", err) - os.Exit(1) + config.DisplayUsageText() + panic(fmt.Errorf("Failed to parse flags: %w", err)) } displayVersion, err := fs.GetBool(config.VersionKey) From 95797af490e384e2e8f40af3202bee6b84021e76 Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Thu, 8 Aug 2024 15:20:59 -0400 Subject: [PATCH 11/30] invert utils.CheckStakeWeightPercentageExceedsThreshold --- signature-aggregator/aggregator/aggregator.go | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/signature-aggregator/aggregator/aggregator.go b/signature-aggregator/aggregator/aggregator.go index 177d7736..3aaae6b5 100644 --- a/signature-aggregator/aggregator/aggregator.go +++ b/signature-aggregator/aggregator/aggregator.go @@ -365,44 +365,44 @@ func (s *SignatureAggregator) handleResponse( } // As soon as the signatures exceed the stake weight threshold we try to aggregate and send the transaction. - if utils.CheckStakeWeightPercentageExceedsThreshold( + if !utils.CheckStakeWeightPercentageExceedsThreshold( accumulatedSignatureWeight, connectedValidators.TotalValidatorWeight, quorumPercentage, ) { - aggSig, vdrBitSet, err := s.aggregateSignatures(signatureMap) - if err != nil { - msg := "Failed to aggregate signature." - s.logger.Error( - msg, - zap.String("sourceBlockchainID", unsignedMessage.SourceChainID.String()), - zap.String("warpMessageID", unsignedMessage.ID().String()), - zap.Error(err), - ) - return nil, true, fmt.Errorf("%s: %w", msg, err) - } + // Not enough signatures, continue processing messages + return nil, true, nil + } + aggSig, vdrBitSet, err := s.aggregateSignatures(signatureMap) + if err != nil { + msg := "Failed to aggregate signature." + s.logger.Error( + msg, + zap.String("sourceBlockchainID", unsignedMessage.SourceChainID.String()), + zap.String("warpMessageID", unsignedMessage.ID().String()), + zap.Error(err), + ) + return nil, true, fmt.Errorf("%s: %w", msg, err) + } - signedMsg, err := avalancheWarp.NewMessage( - unsignedMessage, - &avalancheWarp.BitSetSignature{ - Signers: vdrBitSet.Bytes(), - Signature: *(*[bls.SignatureLen]byte)(bls.SignatureToBytes(aggSig)), - }, + signedMsg, err := avalancheWarp.NewMessage( + unsignedMessage, + &avalancheWarp.BitSetSignature{ + Signers: vdrBitSet.Bytes(), + Signature: *(*[bls.SignatureLen]byte)(bls.SignatureToBytes(aggSig)), + }, + ) + if err != nil { + msg := "Failed to create new signed message" + s.logger.Error( + msg, + zap.String("sourceBlockchainID", unsignedMessage.SourceChainID.String()), + zap.String("warpMessageID", unsignedMessage.ID().String()), + zap.Error(err), ) - if err != nil { - msg := "Failed to create new signed message" - s.logger.Error( - msg, - zap.String("sourceBlockchainID", unsignedMessage.SourceChainID.String()), - zap.String("warpMessageID", unsignedMessage.ID().String()), - zap.Error(err), - ) - return nil, true, fmt.Errorf("%s: %w", msg, err) - } - return signedMsg, true, nil + return nil, true, fmt.Errorf("%s: %w", msg, err) } - // Not enough signatures, continue processing messages - return nil, true, nil + return signedMsg, true, nil } // isValidSignatureResponse tries to generate a signature from the peer.AsyncResponse, then verifies From b8735b08d0d2a984e25d5ae3ef6b8fcb8a012713 Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Thu, 8 Aug 2024 16:46:00 -0400 Subject: [PATCH 12/30] Fix bugs in api and remove old testing code --- go.mod | 4 ++-- go.sum | 8 ++++---- signature-aggregator/aggregator/aggregator.go | 5 +---- signature-aggregator/api/api.go | 3 ++- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 4e3ef774..f9fc152c 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,8 @@ go 1.21.12 require ( github.com/ava-labs/avalanchego v1.11.11-0.20240808144601-8d602b350f59 - github.com/ava-labs/subnet-evm v0.6.9-0.20240806212213-c2da67db92f8 - github.com/ava-labs/teleporter v1.0.5-0.20240808145337-a3092c7f50ea + github.com/ava-labs/subnet-evm v0.6.9-0.20240809021034-3ceec5c96a5f + github.com/ava-labs/teleporter v1.0.5-0.20240809021837-ae1f422baa84 github.com/aws/aws-sdk-go-v2 v1.30.3 github.com/aws/aws-sdk-go-v2/config v1.27.9 github.com/aws/aws-sdk-go-v2/service/kms v1.35.3 diff --git a/go.sum b/go.sum index e4da3ab0..d8804b92 100644 --- a/go.sum +++ b/go.sum @@ -62,10 +62,10 @@ github.com/ava-labs/avalanchego v1.11.11-0.20240808144601-8d602b350f59 h1:Od3s9c github.com/ava-labs/avalanchego v1.11.11-0.20240808144601-8d602b350f59/go.mod h1:Sq26Wg2Yz0k0EzueGMamRzw4apv6wmNi7vPjxX4nNSk= github.com/ava-labs/coreth v0.13.8-0.20240807212152-f7acfafec094 h1:e7TvIKDGzsMsKU3Y4HreRcK7f16EcEPUO04UwSCFtng= github.com/ava-labs/coreth v0.13.8-0.20240807212152-f7acfafec094/go.mod h1:Ouul9dJouniUIJVX1gDqx8CrHyGvmwZkK28mrgKb/4I= -github.com/ava-labs/subnet-evm v0.6.9-0.20240806212213-c2da67db92f8 h1:7G7ABONT72tBC/FSTfKj2sNcqTCo47GKqGeYCtMI0hM= -github.com/ava-labs/subnet-evm v0.6.9-0.20240806212213-c2da67db92f8/go.mod h1:n5jDyKtXZsHxbb5xPOUwhVaKbMCU/oTNTnBjn8Nfau0= -github.com/ava-labs/teleporter v1.0.5-0.20240808145337-a3092c7f50ea h1:4O1KXIpxbxQMWueo9K0ZMvYFj7znb1qbBUnFP/CuMfw= -github.com/ava-labs/teleporter v1.0.5-0.20240808145337-a3092c7f50ea/go.mod h1:9f05xmaQ2IXn4D4jcuHQdyqyn8g+IIT+CaynQQqnI0M= +github.com/ava-labs/subnet-evm v0.6.9-0.20240809021034-3ceec5c96a5f h1:moqjaNZ1RSXL2/yYUXvwSEpIWjmXcWxTORMBHWuwrtE= +github.com/ava-labs/subnet-evm v0.6.9-0.20240809021034-3ceec5c96a5f/go.mod h1:DM/HccJ8PghYk7fA3Cq76OOoVprOtyITICkjwuzEPfg= +github.com/ava-labs/teleporter v1.0.5-0.20240809021837-ae1f422baa84 h1:rZZZ1O5vDc+qSkBzA6SefJJQi8azip0KNAPv9irOW8U= +github.com/ava-labs/teleporter v1.0.5-0.20240809021837-ae1f422baa84/go.mod h1:J9F+AiUImkNaKIqszwTp+eUhYJsMq7Pcdit10jn0IzQ= github.com/aws/aws-sdk-go-v2 v1.30.3 h1:jUeBtG0Ih+ZIFH0F4UkmL9w3cSpaMv9tYYDbzILP8dY= github.com/aws/aws-sdk-go-v2 v1.30.3/go.mod h1:nIQjQVp5sfpQcTc9mPSr1B0PaWK5ByX9MOoDadSN4lc= github.com/aws/aws-sdk-go-v2/config v1.27.9 h1:gRx/NwpNEFSk+yQlgmk1bmxxvQ5TyJ76CWXs9XScTqg= diff --git a/signature-aggregator/aggregator/aggregator.go b/signature-aggregator/aggregator/aggregator.go index 3aaae6b5..8461b5a8 100644 --- a/signature-aggregator/aggregator/aggregator.go +++ b/signature-aggregator/aggregator/aggregator.go @@ -5,7 +5,6 @@ package aggregator import ( "bytes" - "encoding/binary" "errors" "fmt" "math/big" @@ -120,9 +119,7 @@ func (s *SignatureAggregator) CreateSignedMessage( ) return nil, errNotEnoughConnectedStake } - numBytes := make([]byte, 8) - // Convert the uint64 to a byte slice using big-endian encoding - binary.BigEndian.PutUint64(numBytes, networkP2P.SignatureRequestHandlerID) + reqBytes := networkP2P.ProtocolPrefix(networkP2P.SignatureRequestHandlerID) messageBytes, err := proto.Marshal( &sdk.SignatureRequest{Message: unsignedMessage.Bytes()}, diff --git a/signature-aggregator/api/api.go b/signature-aggregator/api/api.go index 810ab954..a021aba2 100644 --- a/signature-aggregator/api/api.go +++ b/signature-aggregator/api/api.go @@ -123,12 +123,13 @@ func signatureAggregationAPIHandler(logger logging.Logger, aggregator *aggregato return } - if isEmptyOrZeroes(message.Bytes()) || isEmptyOrZeroes(justification) { + if isEmptyOrZeroes(message.Bytes()) && isEmptyOrZeroes(justification) { writeJSONError( logger, w, "Must provide either message or justification", ) + return } quorumPercentage := req.QuorumPercentage From 0be46eb59c5caa972f80bbc7c7887a3d464b01fb Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Thu, 8 Aug 2024 22:44:50 -0400 Subject: [PATCH 13/30] bump teleporter submodule --- tests/contracts/lib/teleporter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/contracts/lib/teleporter b/tests/contracts/lib/teleporter index 8b7d7245..a3092c7f 160000 --- a/tests/contracts/lib/teleporter +++ b/tests/contracts/lib/teleporter @@ -1 +1 @@ -Subproject commit 8b7d7245d6998f14a0655b86670c998ba5e5f964 +Subproject commit a3092c7f50ea749e2ecbf2cbc7df2e3fd8b78581 From 79132a1ef76e2ebe313646d3393f0c3d88f2f337 Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Thu, 8 Aug 2024 23:10:12 -0400 Subject: [PATCH 14/30] actually fix versions --- go.mod | 2 +- go.sum | 4 ++-- scripts/versions.sh | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index f9fc152c..51e6f2e9 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/ava-labs/awm-relayer go 1.21.12 require ( - github.com/ava-labs/avalanchego v1.11.11-0.20240808144601-8d602b350f59 + github.com/ava-labs/avalanchego v1.11.11-0.20240807214427-376688b4912b github.com/ava-labs/subnet-evm v0.6.9-0.20240809021034-3ceec5c96a5f github.com/ava-labs/teleporter v1.0.5-0.20240809021837-ae1f422baa84 github.com/aws/aws-sdk-go-v2 v1.30.3 diff --git a/go.sum b/go.sum index d8804b92..5660042b 100644 --- a/go.sum +++ b/go.sum @@ -58,8 +58,8 @@ github.com/alexliesenfeld/health v0.8.0/go.mod h1:TfNP0f+9WQVWMQRzvMUjlws4ceXKEL github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/ava-labs/avalanchego v1.11.11-0.20240808144601-8d602b350f59 h1:Od3s9c4SMDfozvRfVFahPL8IhG8hiPSkJrRuT95XZa0= -github.com/ava-labs/avalanchego v1.11.11-0.20240808144601-8d602b350f59/go.mod h1:Sq26Wg2Yz0k0EzueGMamRzw4apv6wmNi7vPjxX4nNSk= +github.com/ava-labs/avalanchego v1.11.11-0.20240807214427-376688b4912b h1:RVamx4MybSg5cvMTAaLKjJg2vPTaBoXiI3NAk0xfKAs= +github.com/ava-labs/avalanchego v1.11.11-0.20240807214427-376688b4912b/go.mod h1:Sq26Wg2Yz0k0EzueGMamRzw4apv6wmNi7vPjxX4nNSk= github.com/ava-labs/coreth v0.13.8-0.20240807212152-f7acfafec094 h1:e7TvIKDGzsMsKU3Y4HreRcK7f16EcEPUO04UwSCFtng= github.com/ava-labs/coreth v0.13.8-0.20240807212152-f7acfafec094/go.mod h1:Ouul9dJouniUIJVX1gDqx8CrHyGvmwZkK28mrgKb/4I= github.com/ava-labs/subnet-evm v0.6.9-0.20240809021034-3ceec5c96a5f h1:moqjaNZ1RSXL2/yYUXvwSEpIWjmXcWxTORMBHWuwrtE= diff --git a/scripts/versions.sh b/scripts/versions.sh index 62c43b29..4c1651de 100755 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -19,12 +19,12 @@ export GO_VERSION=${GO_VERSION:-$(getDepVersion go)} # Don't export them as they're used in the context of other calls # TODO: undo this hack once go.mod is referring to a tag rather than a commit #AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-$(getDepVersion github.com/ava-labs/avalanchego)} -AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-8d602b350f599fcaa67882dcbed5086feb5579a1} +AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-376688b4912bf1b3c988167cfabf4ebedc27dc16} GINKGO_VERSION=${GINKGO_VERSION:-$(getDepVersion github.com/onsi/ginkgo/v2)} # TODO: undo this hack once go.mod is referring to a tag rather than a commit #SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-$(getDepVersion github.com/ava-labs/subnet-evm)} -SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-v0.6.8-acp-118-handlers} +SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-3ceec5c96a5f83b09d06767fae83e89f79c5c2c6} # Set golangci-lint version GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION:-'v1.55'} From bce634d53eef0f01d4208db5b3bfe6ffa05ae5df Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Mon, 19 Aug 2024 09:59:30 -0400 Subject: [PATCH 15/30] replace feature branch commit references with default branch ones --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- scripts/versions.sh | 4 ++-- tests/contracts/lib/teleporter | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 51e6f2e9..4c55ba82 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/ava-labs/awm-relayer go 1.21.12 require ( - github.com/ava-labs/avalanchego v1.11.11-0.20240807214427-376688b4912b - github.com/ava-labs/subnet-evm v0.6.9-0.20240809021034-3ceec5c96a5f - github.com/ava-labs/teleporter v1.0.5-0.20240809021837-ae1f422baa84 + github.com/ava-labs/avalanchego v1.11.11-0.20240813203340-ab83fb41528d + github.com/ava-labs/subnet-evm v0.6.9-0.20240816202746-18633729a0cd + github.com/ava-labs/teleporter v1.0.4 github.com/aws/aws-sdk-go-v2 v1.30.3 github.com/aws/aws-sdk-go-v2/config v1.27.9 github.com/aws/aws-sdk-go-v2/service/kms v1.35.3 @@ -25,7 +25,7 @@ require ( ) require ( - github.com/ava-labs/coreth v0.13.8-0.20240807212152-f7acfafec094 // indirect + github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240813194342-7635a96aa180 // indirect github.com/aws/aws-sdk-go-v2/credentials v1.17.9 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.0 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.15 // indirect diff --git a/go.sum b/go.sum index 5660042b..0911690c 100644 --- a/go.sum +++ b/go.sum @@ -58,14 +58,14 @@ github.com/alexliesenfeld/health v0.8.0/go.mod h1:TfNP0f+9WQVWMQRzvMUjlws4ceXKEL github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/ava-labs/avalanchego v1.11.11-0.20240807214427-376688b4912b h1:RVamx4MybSg5cvMTAaLKjJg2vPTaBoXiI3NAk0xfKAs= -github.com/ava-labs/avalanchego v1.11.11-0.20240807214427-376688b4912b/go.mod h1:Sq26Wg2Yz0k0EzueGMamRzw4apv6wmNi7vPjxX4nNSk= -github.com/ava-labs/coreth v0.13.8-0.20240807212152-f7acfafec094 h1:e7TvIKDGzsMsKU3Y4HreRcK7f16EcEPUO04UwSCFtng= -github.com/ava-labs/coreth v0.13.8-0.20240807212152-f7acfafec094/go.mod h1:Ouul9dJouniUIJVX1gDqx8CrHyGvmwZkK28mrgKb/4I= -github.com/ava-labs/subnet-evm v0.6.9-0.20240809021034-3ceec5c96a5f h1:moqjaNZ1RSXL2/yYUXvwSEpIWjmXcWxTORMBHWuwrtE= -github.com/ava-labs/subnet-evm v0.6.9-0.20240809021034-3ceec5c96a5f/go.mod h1:DM/HccJ8PghYk7fA3Cq76OOoVprOtyITICkjwuzEPfg= -github.com/ava-labs/teleporter v1.0.5-0.20240809021837-ae1f422baa84 h1:rZZZ1O5vDc+qSkBzA6SefJJQi8azip0KNAPv9irOW8U= -github.com/ava-labs/teleporter v1.0.5-0.20240809021837-ae1f422baa84/go.mod h1:J9F+AiUImkNaKIqszwTp+eUhYJsMq7Pcdit10jn0IzQ= +github.com/ava-labs/avalanchego v1.11.11-0.20240813203340-ab83fb41528d h1:LyrKJL9avIIxBY3uTcS2dFtUMBFmI2QpAgG6qYTdA6s= +github.com/ava-labs/avalanchego v1.11.11-0.20240813203340-ab83fb41528d/go.mod h1:UkyrRDXK2E15Lq2abyae2Pt+JsWvgsg1pe0/AtoMyAM= +github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240813194342-7635a96aa180 h1:6aIHp7wbyGVYdhHVQUbG7BEcbCMEQ5SYopPPJyipyvk= +github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240813194342-7635a96aa180/go.mod h1:/wNBVq7J7wlC2Kbov7kk6LV5xZvau7VF9zwTVOeyAjY= +github.com/ava-labs/subnet-evm v0.6.9-0.20240816202746-18633729a0cd h1:5kJTOhmIhIiobseQ+RYuLg4UyodN+CSAdW1c0hx1R2Y= +github.com/ava-labs/subnet-evm v0.6.9-0.20240816202746-18633729a0cd/go.mod h1:QfIzh7YxKj97jbendOHQbaAxM7SMj5MWdV13o1VLn70= +github.com/ava-labs/teleporter v1.0.4 h1:+OAS3YyPc/LijR29qu3EqU6xAnQnjOgf4EtDlCMcDsc= +github.com/ava-labs/teleporter v1.0.4/go.mod h1:bUiOSIGjFktkYg01XDjeaZdgLEx0ZpUDfJXI6Z0rHY8= github.com/aws/aws-sdk-go-v2 v1.30.3 h1:jUeBtG0Ih+ZIFH0F4UkmL9w3cSpaMv9tYYDbzILP8dY= github.com/aws/aws-sdk-go-v2 v1.30.3/go.mod h1:nIQjQVp5sfpQcTc9mPSr1B0PaWK5ByX9MOoDadSN4lc= github.com/aws/aws-sdk-go-v2/config v1.27.9 h1:gRx/NwpNEFSk+yQlgmk1bmxxvQ5TyJ76CWXs9XScTqg= diff --git a/scripts/versions.sh b/scripts/versions.sh index 4c1651de..f02427ec 100755 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -19,12 +19,12 @@ export GO_VERSION=${GO_VERSION:-$(getDepVersion go)} # Don't export them as they're used in the context of other calls # TODO: undo this hack once go.mod is referring to a tag rather than a commit #AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-$(getDepVersion github.com/ava-labs/avalanchego)} -AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-376688b4912bf1b3c988167cfabf4ebedc27dc16} +AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-ab83fb41528de93c1790301cdd67a07dda9299f0} GINKGO_VERSION=${GINKGO_VERSION:-$(getDepVersion github.com/onsi/ginkgo/v2)} # TODO: undo this hack once go.mod is referring to a tag rather than a commit #SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-$(getDepVersion github.com/ava-labs/subnet-evm)} -SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-3ceec5c96a5f83b09d06767fae83e89f79c5c2c6} +SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-18633729a0cde7d695616e14b77873957a2b59c2} # Set golangci-lint version GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION:-'v1.55'} diff --git a/tests/contracts/lib/teleporter b/tests/contracts/lib/teleporter index a3092c7f..bd88a999 160000 --- a/tests/contracts/lib/teleporter +++ b/tests/contracts/lib/teleporter @@ -1 +1 @@ -Subproject commit a3092c7f50ea749e2ecbf2cbc7df2e3fd8b78581 +Subproject commit bd88a999e3b2b5131837180601c7c798acbac7e2 From 811c97aeb62a4eb888f26c69626cc7cd3addd148 Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Wed, 21 Aug 2024 10:59:55 -0400 Subject: [PATCH 16/30] add explicit check for signature length --- signature-aggregator/aggregator/aggregator.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/signature-aggregator/aggregator/aggregator.go b/signature-aggregator/aggregator/aggregator.go index 8461b5a8..5567c676 100644 --- a/signature-aggregator/aggregator/aggregator.go +++ b/signature-aggregator/aggregator/aggregator.go @@ -448,6 +448,15 @@ func (s *SignatureAggregator) isValidSignatureResponse( return blsSignatureBuf{}, false } + if len(signature) != bls.SignatureLen { + s.logger.Debug( + "Response signature has incorrect length", + zap.Int("actual", len(signature)), + zap.Int("expected", bls.SignatureLen), + ) + return blsSignatureBuf{}, false + } + sig, err := bls.SignatureFromBytes(signature[:]) if err != nil { s.logger.Debug( From 29cac3003f36112564c3545f2647bbe934609e54 Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Wed, 21 Aug 2024 15:49:07 +0000 Subject: [PATCH 17/30] relay justification from handled request to AppReq --- signature-aggregator/aggregator/aggregator.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/signature-aggregator/aggregator/aggregator.go b/signature-aggregator/aggregator/aggregator.go index 3eae4a8d..e62d99a6 100644 --- a/signature-aggregator/aggregator/aggregator.go +++ b/signature-aggregator/aggregator/aggregator.go @@ -170,7 +170,10 @@ func (s *SignatureAggregator) CreateSignedMessage( reqBytes := networkP2P.ProtocolPrefix(networkP2P.SignatureRequestHandlerID) messageBytes, err := proto.Marshal( - &sdk.SignatureRequest{Message: unsignedMessage.Bytes()}, + &sdk.SignatureRequest{ + Message: unsignedMessage.Bytes(), + Justification: justification, + }, ) reqBytes = append(reqBytes, messageBytes...) if err != nil { From 58af3deae462123f6b905f7aeed55a808ab7b5c9 Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Thu, 22 Aug 2024 20:31:46 -0400 Subject: [PATCH 18/30] Update signature-aggregator/api/api.go Co-authored-by: Geoff Stuart Signed-off-by: F. Eugene Aumson --- signature-aggregator/api/api.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/signature-aggregator/api/api.go b/signature-aggregator/api/api.go index 7ced94d2..e12eb19d 100644 --- a/signature-aggregator/api/api.go +++ b/signature-aggregator/api/api.go @@ -26,8 +26,8 @@ const ( // Defines a request interface for signature aggregation for a raw unsigned message. type AggregateSignatureRequest struct { - // Required: either Message or Justification must be provided - // Required. hex-encoded message, optionally prefixed with "0x". + // Required: either Message or Justification must be provided. + // hex-encoded message, optionally prefixed with "0x". Message string `json:"message"` // hex-encoded justification, optionally prefixed with "0x". Justification string `json:"justification"` From 77262bc92f36327fa7fabd3a3b2e74eac534a333 Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Tue, 27 Aug 2024 15:19:15 -0400 Subject: [PATCH 19/30] Etna timestamp switch --- config/api_config.go | 3 + relayer/config/config.go | 2 + relayer/config/keys.go | 1 + relayer/main/main.go | 1 + signature-aggregator/aggregator/aggregator.go | 76 +++++++++++++++---- signature-aggregator/config/config.go | 2 + signature-aggregator/config/keys.go | 1 + signature-aggregator/main/main.go | 1 + 8 files changed, 73 insertions(+), 14 deletions(-) diff --git a/config/api_config.go b/config/api_config.go index 25a77f6a..e68d73c4 100644 --- a/config/api_config.go +++ b/config/api_config.go @@ -1,3 +1,6 @@ +// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + package config import ( diff --git a/relayer/config/config.go b/relayer/config/config.go index 57ea0822..42607383 100644 --- a/relayer/config/config.go +++ b/relayer/config/config.go @@ -8,6 +8,7 @@ import ( "errors" "fmt" "net/url" + "time" basecfg "github.com/ava-labs/awm-relayer/config" "github.com/ava-labs/awm-relayer/peers" @@ -66,6 +67,7 @@ type Config struct { ProcessMissedBlocks bool `mapstructure:"process-missed-blocks" json:"process-missed-blocks"` DeciderURL string `mapstructure:"decider-url" json:"decider-url"` SignatureCacheSize uint64 `mapstructure:"signature-cache-size" json:"signature-cache-size"` + EtnaTime time.Time `mapstructure:"etna-time" json:"etna-time"` // convenience field to fetch a blockchain's subnet ID blockchainIDToSubnetID map[ids.ID]ids.ID diff --git a/relayer/config/keys.go b/relayer/config/keys.go index 1c426fe0..fb446773 100644 --- a/relayer/config/keys.go +++ b/relayer/config/keys.go @@ -24,4 +24,5 @@ const ( ManualWarpMessagesKey = "manual-warp-messages" DBWriteIntervalSecondsKey = "db-write-interval-seconds" SignatureCacheSizeKey = "signature-cache-size" + EtnaTimestampKey = "etna-timestamp" ) diff --git a/relayer/main/main.go b/relayer/main/main.go index 358561c7..3ee92351 100644 --- a/relayer/main/main.go +++ b/relayer/main/main.go @@ -227,6 +227,7 @@ func main() { prometheus.DefaultRegisterer, ), messageCreator, + cfg.EtnaTime, ) if err != nil { logger.Fatal("Failed to create signature aggregator", zap.Error(err)) diff --git a/signature-aggregator/aggregator/aggregator.go b/signature-aggregator/aggregator/aggregator.go index 01817491..b2df4f95 100644 --- a/signature-aggregator/aggregator/aggregator.go +++ b/signature-aggregator/aggregator/aggregator.go @@ -19,6 +19,7 @@ import ( "github.com/ava-labs/avalanchego/proto/pb/p2p" "github.com/ava-labs/avalanchego/proto/pb/sdk" "github.com/ava-labs/avalanchego/subnets" + "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/set" @@ -27,6 +28,8 @@ import ( "github.com/ava-labs/awm-relayer/signature-aggregator/aggregator/cache" "github.com/ava-labs/awm-relayer/signature-aggregator/metrics" "github.com/ava-labs/awm-relayer/utils" + coreEthMsg "github.com/ava-labs/subnet-evm/plugin/evm/message" + msg "github.com/ava-labs/subnet-evm/plugin/evm/message" "go.uber.org/zap" "google.golang.org/protobuf/proto" ) @@ -42,6 +45,9 @@ const ( ) var ( + codec = msg.Codec + coreEthCodec = coreEthMsg.Codec + // Errors errNotEnoughSignatures = errors.New("failed to collect a threshold of signatures") errNotEnoughConnectedStake = errors.New("failed to connect to a threshold of stake") @@ -57,6 +63,7 @@ type SignatureAggregator struct { subnetsMapLock sync.RWMutex metrics *metrics.SignatureAggregatorMetrics cache *cache.Cache + etnaTime time.Time } func NewSignatureAggregator( @@ -65,6 +72,7 @@ func NewSignatureAggregator( signatureCacheSize uint64, metrics *metrics.SignatureAggregatorMetrics, messageCreator message.Creator, + etnaTime time.Time, ) (*SignatureAggregator, error) { cache, err := cache.NewCache(signatureCacheSize, logger) if err != nil { @@ -81,6 +89,7 @@ func NewSignatureAggregator( messageCreator: messageCreator, currentRequestID: atomic.Uint32{}, cache: cache, + etnaTime: etnaTime, } sa.currentRequestID.Store(rand.Uint32()) return &sa, nil @@ -174,14 +183,7 @@ func (s *SignatureAggregator) CreateSignedMessage( )) } - reqBytes := networkP2P.ProtocolPrefix(networkP2P.SignatureRequestHandlerID) - messageBytes, err := proto.Marshal( - &sdk.SignatureRequest{ - Message: unsignedMessage.Bytes(), - Justification: justification, - }, - ) - reqBytes = append(reqBytes, messageBytes...) + reqBytes, err := s.marshalRequest(unsignedMessage, justification, sourceSubnet) if err != nil { msg := "Failed to marshal request bytes" s.logger.Error( @@ -517,15 +519,13 @@ func (s *SignatureAggregator) isValidSignatureResponse( return blsSignatureBuf{}, false } - sigResponse := sdk.SignatureResponse{} - err := proto.Unmarshal(appResponse.AppBytes, &sigResponse) + signature, err := s.unmarshalResponse(appResponse.AppBytes) if err != nil { s.logger.Error( "Error unmarshaling signature response", zap.Error(err), ) } - signature := sigResponse.Signature // If the node returned an empty signature, then it has not yet seen the warp message. Retry later. emptySignature := blsSignatureBuf{} @@ -560,9 +560,8 @@ func (s *SignatureAggregator) isValidSignatureResponse( ) return blsSignatureBuf{}, false } - blsSig := blsSignatureBuf{} - copy(blsSig[:], signature[:]) - return blsSig, true + + return signature, true } // aggregateSignatures constructs a BLS aggregate signature from the collected validator signatures. Also @@ -594,3 +593,52 @@ func (s *SignatureAggregator) aggregateSignatures( } return aggSig, vdrBitSet, nil } + +func (s *SignatureAggregator) marshalRequest(unsignedMessage *avalancheWarp.UnsignedMessage, justification []byte, sourceSubnet ids.ID) ([]byte, error) { + if !s.etnaTime.IsZero() && s.etnaTime.Before(time.Now()) { + reqBytes := networkP2P.ProtocolPrefix(networkP2P.SignatureRequestHandlerID) + messageBytes, err := proto.Marshal( + &sdk.SignatureRequest{ + Message: unsignedMessage.Bytes(), + Justification: justification, + }, + ) + if err != nil { + return []byte{}, err + } + reqBytes = append(reqBytes, messageBytes...) + return reqBytes, nil + } else { + if sourceSubnet == constants.PrimaryNetworkID { + req := coreEthMsg.MessageSignatureRequest{ + MessageID: unsignedMessage.ID(), + } + return coreEthMsg.RequestToBytes(coreEthCodec, req) + } else { + req := msg.MessageSignatureRequest{ + MessageID: unsignedMessage.ID(), + } + return msg.RequestToBytes(codec, req) + } + } +} + +func (s *SignatureAggregator) unmarshalResponse(responseBytes []byte) (blsSignatureBuf, error) { + // Post-Etna case + if !s.etnaTime.IsZero() && s.etnaTime.Before(time.Now()) { + var sigResponse sdk.SignatureResponse + err := proto.Unmarshal(responseBytes, &sigResponse) + if err != nil { + return blsSignatureBuf{}, err + } + return blsSignatureBuf(sigResponse.Signature), nil + } else { + // Pre-Etna case + var sigResponse msg.SignatureResponse + _, err := msg.Codec.Unmarshal(responseBytes, &sigResponse) + if err != nil { + return blsSignatureBuf{}, err + } + return sigResponse.Signature, nil + } +} diff --git a/signature-aggregator/config/config.go b/signature-aggregator/config/config.go index 19b769d2..7dfe1846 100644 --- a/signature-aggregator/config/config.go +++ b/signature-aggregator/config/config.go @@ -5,6 +5,7 @@ package config import ( "fmt" + "time" "github.com/ava-labs/avalanchego/utils/logging" basecfg "github.com/ava-labs/awm-relayer/config" @@ -34,6 +35,7 @@ type Config struct { APIPort uint16 `mapstructure:"api-port" json:"api-port"` MetricsPort uint16 `mapstructure:"metrics-port" json:"metrics-port"` SignatureCacheSize uint64 `mapstructure:"signature-cache-size" json:"signature-cache-size"` + EtnaTime time.Time `mapstructure:"etna-time" json:"etna-time"` } func DisplayUsageText() { diff --git a/signature-aggregator/config/keys.go b/signature-aggregator/config/keys.go index 97829f77..d2f3e077 100644 --- a/signature-aggregator/config/keys.go +++ b/signature-aggregator/config/keys.go @@ -16,4 +16,5 @@ const ( APIPortKey = "api-port" MetricsPortKey = "metrics-port" SignatureCacheSizeKey = "signature-cache-size" + EtnaTimeKey = "etna-time" ) diff --git a/signature-aggregator/main/main.go b/signature-aggregator/main/main.go index 69b619a1..27edfd3b 100644 --- a/signature-aggregator/main/main.go +++ b/signature-aggregator/main/main.go @@ -117,6 +117,7 @@ func main() { cfg.SignatureCacheSize, metricsInstance, messageCreator, + cfg.EtnaTime, ) if err != nil { logger.Fatal("Failed to create signature aggregator", zap.Error(err)) From ec5b830a3a2299c0ecb8ef1115d2d71c826a1cbe Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Wed, 28 Aug 2024 09:57:57 -0400 Subject: [PATCH 20/30] Fix implementation and add E2E test --- relayer/config/config.go | 4 +- relayer/config/keys.go | 2 +- relayer/config/viper.go | 3 + signature-aggregator/aggregator/aggregator.go | 20 ++-- signature-aggregator/config/config.go | 4 +- signature-aggregator/config/viper.go | 3 + tests/e2e_test.go | 3 + tests/etna_upgrade.go | 109 ++++++++++++++++++ 8 files changed, 138 insertions(+), 10 deletions(-) create mode 100644 tests/etna_upgrade.go diff --git a/relayer/config/config.go b/relayer/config/config.go index 42607383..3f643dd2 100644 --- a/relayer/config/config.go +++ b/relayer/config/config.go @@ -67,7 +67,9 @@ type Config struct { ProcessMissedBlocks bool `mapstructure:"process-missed-blocks" json:"process-missed-blocks"` DeciderURL string `mapstructure:"decider-url" json:"decider-url"` SignatureCacheSize uint64 `mapstructure:"signature-cache-size" json:"signature-cache-size"` - EtnaTime time.Time `mapstructure:"etna-time" json:"etna-time"` + + // mapstructure doesn't handle time.Time out of the box so handle it manually + EtnaTime time.Time `json:"etna-time"` // convenience field to fetch a blockchain's subnet ID blockchainIDToSubnetID map[ids.ID]ids.ID diff --git a/relayer/config/keys.go b/relayer/config/keys.go index fb446773..fa211fc2 100644 --- a/relayer/config/keys.go +++ b/relayer/config/keys.go @@ -24,5 +24,5 @@ const ( ManualWarpMessagesKey = "manual-warp-messages" DBWriteIntervalSecondsKey = "db-write-interval-seconds" SignatureCacheSizeKey = "signature-cache-size" - EtnaTimestampKey = "etna-timestamp" + EtnaTimeKey = "etna-time" ) diff --git a/relayer/config/viper.go b/relayer/config/viper.go index 507bd952..4e0e279b 100644 --- a/relayer/config/viper.go +++ b/relayer/config/viper.go @@ -84,6 +84,9 @@ func BuildConfig(v *viper.Viper) (Config, error) { return cfg, fmt.Errorf("failed to unmarshal viper config: %w", err) } + // Manually set EtnaTime field since it's not automatically parseable using mapstructure + cfg.EtnaTime = v.GetTime(EtnaTimeKey) + // Explicitly overwrite the configured account private key // If account-private-key is set as a flag or environment variable, // overwrite all destination subnet configurations to use that key diff --git a/signature-aggregator/aggregator/aggregator.go b/signature-aggregator/aggregator/aggregator.go index b2df4f95..c971526b 100644 --- a/signature-aggregator/aggregator/aggregator.go +++ b/signature-aggregator/aggregator/aggregator.go @@ -28,7 +28,7 @@ import ( "github.com/ava-labs/awm-relayer/signature-aggregator/aggregator/cache" "github.com/ava-labs/awm-relayer/signature-aggregator/metrics" "github.com/ava-labs/awm-relayer/utils" - coreEthMsg "github.com/ava-labs/subnet-evm/plugin/evm/message" + corethMsg "github.com/ava-labs/coreth/plugin/evm/message" msg "github.com/ava-labs/subnet-evm/plugin/evm/message" "go.uber.org/zap" "google.golang.org/protobuf/proto" @@ -45,8 +45,8 @@ const ( ) var ( - codec = msg.Codec - coreEthCodec = coreEthMsg.Codec + codec = msg.Codec + corethCodec = corethMsg.Codec // Errors errNotEnoughSignatures = errors.New("failed to collect a threshold of signatures") @@ -594,8 +594,13 @@ func (s *SignatureAggregator) aggregateSignatures( return aggSig, vdrBitSet, nil } -func (s *SignatureAggregator) marshalRequest(unsignedMessage *avalancheWarp.UnsignedMessage, justification []byte, sourceSubnet ids.ID) ([]byte, error) { +func (s *SignatureAggregator) marshalRequest( + unsignedMessage *avalancheWarp.UnsignedMessage, + justification []byte, + sourceSubnet ids.ID, +) ([]byte, error) { if !s.etnaTime.IsZero() && s.etnaTime.Before(time.Now()) { + // Post-Etna case reqBytes := networkP2P.ProtocolPrefix(networkP2P.SignatureRequestHandlerID) messageBytes, err := proto.Marshal( &sdk.SignatureRequest{ @@ -609,11 +614,12 @@ func (s *SignatureAggregator) marshalRequest(unsignedMessage *avalancheWarp.Unsi reqBytes = append(reqBytes, messageBytes...) return reqBytes, nil } else { + // Pre-Etna case if sourceSubnet == constants.PrimaryNetworkID { - req := coreEthMsg.MessageSignatureRequest{ + req := corethMsg.MessageSignatureRequest{ MessageID: unsignedMessage.ID(), } - return coreEthMsg.RequestToBytes(coreEthCodec, req) + return corethMsg.RequestToBytes(corethCodec, req) } else { req := msg.MessageSignatureRequest{ MessageID: unsignedMessage.ID(), @@ -624,8 +630,8 @@ func (s *SignatureAggregator) marshalRequest(unsignedMessage *avalancheWarp.Unsi } func (s *SignatureAggregator) unmarshalResponse(responseBytes []byte) (blsSignatureBuf, error) { - // Post-Etna case if !s.etnaTime.IsZero() && s.etnaTime.Before(time.Now()) { + // Post-Etna case var sigResponse sdk.SignatureResponse err := proto.Unmarshal(responseBytes, &sigResponse) if err != nil { diff --git a/signature-aggregator/config/config.go b/signature-aggregator/config/config.go index 7dfe1846..ec6d570e 100644 --- a/signature-aggregator/config/config.go +++ b/signature-aggregator/config/config.go @@ -35,7 +35,9 @@ type Config struct { APIPort uint16 `mapstructure:"api-port" json:"api-port"` MetricsPort uint16 `mapstructure:"metrics-port" json:"metrics-port"` SignatureCacheSize uint64 `mapstructure:"signature-cache-size" json:"signature-cache-size"` - EtnaTime time.Time `mapstructure:"etna-time" json:"etna-time"` + + // mapstructure doesn't support time.Time out of the box so handle it manually + EtnaTime time.Time `json:"etna-time"` } func DisplayUsageText() { diff --git a/signature-aggregator/config/viper.go b/signature-aggregator/config/viper.go index dc33f918..0ca4a410 100644 --- a/signature-aggregator/config/viper.go +++ b/signature-aggregator/config/viper.go @@ -76,5 +76,8 @@ func BuildConfig(v *viper.Viper) (Config, error) { return cfg, fmt.Errorf("failed to unmarshal viper config: %w", err) } + // mapstructure doesn't support time.Time out of the box so handle it manually + cfg.EtnaTime = v.GetTime(EtnaTimeKey) + return cfg, nil } diff --git a/tests/e2e_test.go b/tests/e2e_test.go index 48a61808..4a475334 100644 --- a/tests/e2e_test.go +++ b/tests/e2e_test.go @@ -174,4 +174,7 @@ var _ = ginkgo.Describe("[AWM Relayer Integration Tests", func() { ginkgo.It("Signature Aggregator", func() { SignatureAggregatorAPI(localNetworkInstance) }) + ginkgo.It("Etna Upgrade", func() { + EtnaUpgrade(localNetworkInstance) + }) }) diff --git a/tests/etna_upgrade.go b/tests/etna_upgrade.go new file mode 100644 index 00000000..044d8891 --- /dev/null +++ b/tests/etna_upgrade.go @@ -0,0 +1,109 @@ +// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package tests + +import ( + "context" + "time" + + testUtils "github.com/ava-labs/awm-relayer/tests/utils" + "github.com/ava-labs/teleporter/tests/interfaces" + "github.com/ava-labs/teleporter/tests/utils" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/log" + . "github.com/onsi/gomega" +) + +// This tests basic functionality of the relayer in the context +// of Etna network upgrade using the following cases: +// - Relaying from Subnet A to Subnet B using Pre-Etna config +// - Relaying from Subnet B to Subnet A using Post-Etna config +func EtnaUpgrade(network interfaces.LocalNetwork) { + subnetAInfo := network.GetPrimaryNetworkInfo() + subnetBInfo, _ := utils.GetTwoSubnets(network) + fundedAddress, fundedKey := network.GetFundedAccountInfo() + teleporterContractAddress := network.GetTeleporterContractAddress() + err := testUtils.ClearRelayerStorage() + Expect(err).Should(BeNil()) + // + // Fund the relayer address on all subnets + // + ctx := context.Background() + + log.Info("Funding relayer address on all subnets") + relayerKey, err := crypto.GenerateKey() + Expect(err).Should(BeNil()) + testUtils.FundRelayers(ctx, []interfaces.SubnetTestInfo{subnetAInfo, subnetBInfo}, fundedKey, relayerKey) + + // + // Set up relayer config + // + relayerConfig := testUtils.CreateDefaultRelayerConfig( + []interfaces.SubnetTestInfo{subnetAInfo, subnetBInfo}, + []interfaces.SubnetTestInfo{subnetAInfo, subnetBInfo}, + teleporterContractAddress, + fundedAddress, + relayerKey, + ) + relayerConfig.EtnaTime = time.Now().AddDate(0, 0, 1) + // The config needs to be validated in order to be passed to database.GetConfigRelayerIDs + relayerConfig.Validate() + + relayerConfigPath := testUtils.WriteRelayerConfig(relayerConfig, testUtils.DefaultRelayerCfgFname) + + // + // Test Relaying from Subnet A to Subnet B + // + log.Info("Test Relaying from Subnet A to Subnet B") + + log.Info("Starting the relayer") + relayerCleanup, readyChan := testUtils.RunRelayerExecutable( + ctx, + relayerConfigPath, + relayerConfig, + ) + defer relayerCleanup() + + // Wait for relayer to start up + startupCtx, startupCancel := context.WithTimeout(ctx, 15*time.Second) + defer startupCancel() + testUtils.WaitForChannelClose(startupCtx, readyChan) + + log.Info("Sending transaction from Subnet A to Subnet B, Pre-Etna") + testUtils.RelayBasicMessage( + ctx, + subnetAInfo, + subnetBInfo, + teleporterContractAddress, + fundedKey, + fundedAddress, + ) + // Shutdown the relayer and write a new config with EtnaTime set to yesterday + relayerCleanup() + + relayerConfig.EtnaTime = time.Now().AddDate(0, 0, -1) + relayerConfigPath = testUtils.WriteRelayerConfig(relayerConfig, testUtils.DefaultRelayerCfgFname) + + relayerCleanup, readyChan = testUtils.RunRelayerExecutable( + ctx, + relayerConfigPath, + relayerConfig, + ) + defer relayerCleanup() + + // Wait for relayer to start up + startupCtx, startupCancel = context.WithTimeout(ctx, 15*time.Second) + defer startupCancel() + testUtils.WaitForChannelClose(startupCtx, readyChan) + + log.Info("Test Relaying from Subnet B to Subnet A - Post-Etna") + testUtils.RelayBasicMessage( + ctx, + subnetBInfo, + subnetAInfo, + teleporterContractAddress, + fundedKey, + fundedAddress, + ) +} From 0498f4af6f9f280f430c6c60c51c01291e197cd7 Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Wed, 28 Aug 2024 10:34:59 -0400 Subject: [PATCH 21/30] update sample workflow docs for sig-agg --- signature-aggregator/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/signature-aggregator/README.md b/signature-aggregator/README.md index 413a65d6..3f8b02ac 100644 --- a/signature-aggregator/README.md +++ b/signature-aggregator/README.md @@ -59,9 +59,9 @@ curl --location 'https://api.avax-test.network/ext/bc/C/rpc' \ The topic of the message will be `0x56600c567728a800c0aa927500f831cb451df66a7af570eb4df4dfbf4674887d` which is the output of`cast keccak "SendWarpMessage(address,bytes32,bytes)"` 4. Use the data field of the log message found in step 2 and send it to the locally running service via curl. ```bash -curl --location 'http://localhost:8080/aggregate-signatures/by-raw-message' \ +curl --location 'http://localhost:8080/aggregate-signatures' \ --header 'Content-Type: application/json' \ --data '{ - "data": "", + "message": "" }' ``` From 440a52d0f8ba81295ec7d7b9f57a4c80bc65bd89 Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Wed, 28 Aug 2024 10:51:44 -0400 Subject: [PATCH 22/30] use PrefixMessage function to construct request bytes --- signature-aggregator/aggregator/aggregator.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/signature-aggregator/aggregator/aggregator.go b/signature-aggregator/aggregator/aggregator.go index c971526b..47730e10 100644 --- a/signature-aggregator/aggregator/aggregator.go +++ b/signature-aggregator/aggregator/aggregator.go @@ -601,7 +601,6 @@ func (s *SignatureAggregator) marshalRequest( ) ([]byte, error) { if !s.etnaTime.IsZero() && s.etnaTime.Before(time.Now()) { // Post-Etna case - reqBytes := networkP2P.ProtocolPrefix(networkP2P.SignatureRequestHandlerID) messageBytes, err := proto.Marshal( &sdk.SignatureRequest{ Message: unsignedMessage.Bytes(), @@ -609,10 +608,12 @@ func (s *SignatureAggregator) marshalRequest( }, ) if err != nil { - return []byte{}, err + return nil, err } - reqBytes = append(reqBytes, messageBytes...) - return reqBytes, nil + return networkP2P.PrefixMessage( + networkP2P.ProtocolPrefix(networkP2P.SignatureRequestHandlerID), + messageBytes, + ), nil } else { // Pre-Etna case if sourceSubnet == constants.PrimaryNetworkID { From 91c5016b39b588b6d746196dfaf80503bb80df87 Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Wed, 28 Aug 2024 11:58:08 -0400 Subject: [PATCH 23/30] make etna upgrade test just test the post-etna case --- tests/etna_upgrade.go | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/tests/etna_upgrade.go b/tests/etna_upgrade.go index 044d8891..ce39d824 100644 --- a/tests/etna_upgrade.go +++ b/tests/etna_upgrade.go @@ -15,10 +15,11 @@ import ( . "github.com/onsi/gomega" ) -// This tests basic functionality of the relayer in the context -// of Etna network upgrade using the following cases: -// - Relaying from Subnet A to Subnet B using Pre-Etna config -// - Relaying from Subnet B to Subnet A using Post-Etna config +// This tests basic functionality of the relayer post-etna upgrade +// since other tests write zero value of time.Time +// to the config and therefore are testing the pre-etna case +// - Relaying from Subnet A to Subnet B +// - Relaying from Subnet B to Subnet A func EtnaUpgrade(network interfaces.LocalNetwork) { subnetAInfo := network.GetPrimaryNetworkInfo() subnetBInfo, _ := utils.GetTwoSubnets(network) @@ -46,7 +47,7 @@ func EtnaUpgrade(network interfaces.LocalNetwork) { fundedAddress, relayerKey, ) - relayerConfig.EtnaTime = time.Now().AddDate(0, 0, 1) + relayerConfig.EtnaTime = time.Now().AddDate(0, 0, -1) // The config needs to be validated in order to be passed to database.GetConfigRelayerIDs relayerConfig.Validate() @@ -70,7 +71,7 @@ func EtnaUpgrade(network interfaces.LocalNetwork) { defer startupCancel() testUtils.WaitForChannelClose(startupCtx, readyChan) - log.Info("Sending transaction from Subnet A to Subnet B, Pre-Etna") + log.Info("Sending transaction from Subnet A to Subnet B") testUtils.RelayBasicMessage( ctx, subnetAInfo, @@ -79,25 +80,8 @@ func EtnaUpgrade(network interfaces.LocalNetwork) { fundedKey, fundedAddress, ) - // Shutdown the relayer and write a new config with EtnaTime set to yesterday - relayerCleanup() - - relayerConfig.EtnaTime = time.Now().AddDate(0, 0, -1) - relayerConfigPath = testUtils.WriteRelayerConfig(relayerConfig, testUtils.DefaultRelayerCfgFname) - - relayerCleanup, readyChan = testUtils.RunRelayerExecutable( - ctx, - relayerConfigPath, - relayerConfig, - ) - defer relayerCleanup() - - // Wait for relayer to start up - startupCtx, startupCancel = context.WithTimeout(ctx, 15*time.Second) - defer startupCancel() - testUtils.WaitForChannelClose(startupCtx, readyChan) - log.Info("Test Relaying from Subnet B to Subnet A - Post-Etna") + log.Info("Test Relaying from Subnet B to Subnet A") testUtils.RelayBasicMessage( ctx, subnetBInfo, From 47cfef6a6b259bffb04a75b97e108f2186bb8e25 Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Wed, 28 Aug 2024 14:12:30 -0400 Subject: [PATCH 24/30] use extract_commit instead of manually synced references in versions.sh --- scripts/versions.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/scripts/versions.sh b/scripts/versions.sh index 018f5d67..743d02ad 100755 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -13,18 +13,22 @@ function getDepVersion() { grep -m1 "^\s*$1" $BASE_PATH/go.mod | cut -d ' ' -f2 } +function extract_commit() { + local version=$1 + if [[ $version == *-* ]]; then + # Extract the substring after the last '-' + version=${version##*-} + fi + echo "$version" +} + # This needs to be exported to be picked up by the dockerfile. export GO_VERSION=${GO_VERSION:-$(getDepVersion go)} # Don't export them as they're used in the context of other calls -# TODO: undo this hack once go.mod is referring to a tag rather than a commit -#AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-$(getDepVersion github.com/ava-labs/avalanchego)} -AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-ab83fb41528de93c1790301cdd67a07dda9299f0} -GINKGO_VERSION=${GINKGO_VERSION:-$(getDepVersion github.com/onsi/ginkgo/v2)} - -# TODO: undo this hack once go.mod is referring to a tag rather than a commit -#SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-$(getDepVersion github.com/ava-labs/subnet-evm)} -SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-18633729a0cde7d695616e14b77873957a2b59c2} +AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-$(extract_commit "$(getDepVersion github.com/ava-labs/avalanchego)")} +GINKGO_VERSION=${GINKGO_VERSION:-$(extract_commit "$(getDepVersion github.com/onsi/ginkgo/v2)")} +SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-$(extract_commit "$(getDepVersion github.com/ava-labs/subnet-evm)")} # Set golangci-lint version GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION:-'v1.60'} From b87bcc1275f90ea1f720e46c434cad5ba9ec4ca7 Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Thu, 29 Aug 2024 10:02:52 -0400 Subject: [PATCH 25/30] Revert "use extract_commit instead of manually synced references in versions.sh" This reverts commit 47cfef6a6b259bffb04a75b97e108f2186bb8e25. --- scripts/versions.sh | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/scripts/versions.sh b/scripts/versions.sh index 743d02ad..018f5d67 100755 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -13,22 +13,18 @@ function getDepVersion() { grep -m1 "^\s*$1" $BASE_PATH/go.mod | cut -d ' ' -f2 } -function extract_commit() { - local version=$1 - if [[ $version == *-* ]]; then - # Extract the substring after the last '-' - version=${version##*-} - fi - echo "$version" -} - # This needs to be exported to be picked up by the dockerfile. export GO_VERSION=${GO_VERSION:-$(getDepVersion go)} # Don't export them as they're used in the context of other calls -AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-$(extract_commit "$(getDepVersion github.com/ava-labs/avalanchego)")} -GINKGO_VERSION=${GINKGO_VERSION:-$(extract_commit "$(getDepVersion github.com/onsi/ginkgo/v2)")} -SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-$(extract_commit "$(getDepVersion github.com/ava-labs/subnet-evm)")} +# TODO: undo this hack once go.mod is referring to a tag rather than a commit +#AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-$(getDepVersion github.com/ava-labs/avalanchego)} +AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-ab83fb41528de93c1790301cdd67a07dda9299f0} +GINKGO_VERSION=${GINKGO_VERSION:-$(getDepVersion github.com/onsi/ginkgo/v2)} + +# TODO: undo this hack once go.mod is referring to a tag rather than a commit +#SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-$(getDepVersion github.com/ava-labs/subnet-evm)} +SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-18633729a0cde7d695616e14b77873957a2b59c2} # Set golangci-lint version GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION:-'v1.60'} From 7f9488c75e5934004f4b9430571b6e32af9c8619 Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Fri, 30 Aug 2024 09:30:12 -0400 Subject: [PATCH 26/30] Add TODO to cleanup after Etna release --- signature-aggregator/aggregator/aggregator.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/signature-aggregator/aggregator/aggregator.go b/signature-aggregator/aggregator/aggregator.go index 47730e10..cea134a7 100644 --- a/signature-aggregator/aggregator/aggregator.go +++ b/signature-aggregator/aggregator/aggregator.go @@ -594,6 +594,8 @@ func (s *SignatureAggregator) aggregateSignatures( return aggSig, vdrBitSet, nil } +// TODO: refactor this to remove special handling based on etnaTime +// after Etna release, along with related config and testing code func (s *SignatureAggregator) marshalRequest( unsignedMessage *avalancheWarp.UnsignedMessage, justification []byte, From ca069342e8e426429dea9e5e8d7c4813cdd47ab3 Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Wed, 4 Sep 2024 19:07:14 +0000 Subject: [PATCH 27/30] adapt to latest changes in `main` --- signature-aggregator/aggregator/aggregator_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/signature-aggregator/aggregator/aggregator_test.go b/signature-aggregator/aggregator/aggregator_test.go index 13a6952c..faa21608 100644 --- a/signature-aggregator/aggregator/aggregator_test.go +++ b/signature-aggregator/aggregator/aggregator_test.go @@ -2,6 +2,7 @@ package aggregator import ( "testing" + "time" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/message" @@ -43,6 +44,7 @@ func instantiateAggregator(t *testing.T) ( 1024, sigAggMetrics, messageCreator, + time.Now().Add(-1*time.Minute), ) require.Equal(t, err, nil) return aggregator, mockNetwork @@ -61,7 +63,7 @@ func TestCreateSignedMessageFailsWithNoValidators(t *testing.T) { }, nil, ) - _, err = aggregator.CreateSignedMessage(msg, ids.Empty, 80) + _, err = aggregator.CreateSignedMessage(msg, nil, ids.Empty, 80) require.ErrorContains(t, err, "no signatures") } @@ -78,7 +80,7 @@ func TestCreateSignedMessageFailsWithoutSufficientConnectedStake(t *testing.T) { }, nil, ) - _, err = aggregator.CreateSignedMessage(msg, ids.Empty, 80) + _, err = aggregator.CreateSignedMessage(msg, nil, ids.Empty, 80) require.ErrorContains( t, err, From 6cd8245fdd8a437b47826484ffc3ebe78ead8984 Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Wed, 4 Sep 2024 19:07:39 +0000 Subject: [PATCH 28/30] pass nil, not empty slice addresses review comment https://github.com/ava-labs/awm-relayer/pull/408#discussion_r1734763562 --- relayer/application_relayer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relayer/application_relayer.go b/relayer/application_relayer.go index 1465b69d..c1c93910 100644 --- a/relayer/application_relayer.go +++ b/relayer/application_relayer.go @@ -204,7 +204,7 @@ func (r *ApplicationRelayer) ProcessMessage(handler messages.MessageHandler) (co if r.sourceWarpSignatureClient == nil { signedMessage, err = r.signatureAggregator.CreateSignedMessage( unsignedMessage, - make([]byte, 0), + nil, r.signingSubnetID, r.warpQuorum.QuorumNumerator, ) From 3d7707dc370ad953a957f6297b9f03cfd27c9431 Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Thu, 5 Sep 2024 14:26:15 -0400 Subject: [PATCH 29/30] address review feedback --- signature-aggregator/aggregator/aggregator_test.go | 1 + signature-aggregator/api/api.go | 2 +- tests/etna_upgrade.go | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/signature-aggregator/aggregator/aggregator_test.go b/signature-aggregator/aggregator/aggregator_test.go index faa21608..8876a646 100644 --- a/signature-aggregator/aggregator/aggregator_test.go +++ b/signature-aggregator/aggregator/aggregator_test.go @@ -44,6 +44,7 @@ func instantiateAggregator(t *testing.T) ( 1024, sigAggMetrics, messageCreator, + // Setting the etnaTime to a minute ago so that the post-etna code path is used in the test time.Now().Add(-1*time.Minute), ) require.Equal(t, err, nil) diff --git a/signature-aggregator/api/api.go b/signature-aggregator/api/api.go index e12eb19d..1717b3a9 100644 --- a/signature-aggregator/api/api.go +++ b/signature-aggregator/api/api.go @@ -127,7 +127,7 @@ func signatureAggregationAPIHandler( } justification, err := hex.DecodeString( - strings.TrimPrefix(req.Justification, "0x"), + utils.SanitizeHexString(req.Justification), ) if err != nil { msg := "Could not decode justification" diff --git a/tests/etna_upgrade.go b/tests/etna_upgrade.go index ce39d824..02ab768c 100644 --- a/tests/etna_upgrade.go +++ b/tests/etna_upgrade.go @@ -47,6 +47,7 @@ func EtnaUpgrade(network interfaces.LocalNetwork) { fundedAddress, relayerKey, ) + // Setting the EtnaTime to yesterday so that the post-etna logic path is used. relayerConfig.EtnaTime = time.Now().AddDate(0, 0, -1) // The config needs to be validated in order to be passed to database.GetConfigRelayerIDs relayerConfig.Validate() From 576a375a09e62fb29bd456b5af75ca177b55df62 Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Thu, 5 Sep 2024 15:20:33 -0400 Subject: [PATCH 30/30] address review feedback --- signature-aggregator/aggregator/aggregator.go | 8 ++++++-- tests/utils/utils.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/signature-aggregator/aggregator/aggregator.go b/signature-aggregator/aggregator/aggregator.go index 6878a744..a284c224 100644 --- a/signature-aggregator/aggregator/aggregator.go +++ b/signature-aggregator/aggregator/aggregator.go @@ -601,7 +601,7 @@ func (s *SignatureAggregator) marshalRequest( justification []byte, sourceSubnet ids.ID, ) ([]byte, error) { - if !s.etnaTime.IsZero() && s.etnaTime.Before(time.Now()) { + if s.etnaActivated() { // Post-Etna case messageBytes, err := proto.Marshal( &sdk.SignatureRequest{ @@ -633,7 +633,7 @@ func (s *SignatureAggregator) marshalRequest( } func (s *SignatureAggregator) unmarshalResponse(responseBytes []byte) (blsSignatureBuf, error) { - if !s.etnaTime.IsZero() && s.etnaTime.Before(time.Now()) { + if s.etnaActivated() { // Post-Etna case var sigResponse sdk.SignatureResponse err := proto.Unmarshal(responseBytes, &sigResponse) @@ -651,3 +651,7 @@ func (s *SignatureAggregator) unmarshalResponse(responseBytes []byte) (blsSignat return sigResponse.Signature, nil } } + +func (s *SignatureAggregator) etnaActivated() bool { + return !s.etnaTime.IsZero() && s.etnaTime.Before(time.Now()) +} diff --git a/tests/utils/utils.go b/tests/utils/utils.go index 0ab69f80..70974a4b 100644 --- a/tests/utils/utils.go +++ b/tests/utils/utils.go @@ -228,7 +228,7 @@ func CreateDefaultSignatureAggregatorConfig( ) // Construct the config values for each subnet return signatureaggregatorcfg.Config{ - LogLevel: logging.Debug.LowerString(), + LogLevel: logging.Info.LowerString(), PChainAPI: &config.APIConfig{ BaseURL: sourceSubnetsInfo[0].NodeURIs[0], },