-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add etna-time
configs
#463
Merged
Merged
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
77262bc
Etna timestamp switch
iansuvak ec5b830
Fix implementation and add E2E test
iansuvak 0498f4a
update sample workflow docs for sig-agg
iansuvak 440a52d
use PrefixMessage function to construct request bytes
iansuvak 91c5016
make etna upgrade test just test the post-etna case
iansuvak 47cfef6
use extract_commit instead of manually synced references in versions.sh
iansuvak 5306803
Bump github.com/onsi/ginkgo/v2 from 2.20.1 to 2.20.2
dependabot[bot] b87bcc1
Revert "use extract_commit instead of manually synced references in v…
iansuvak 1143e55
Merge pull request #465 from ava-labs/dependabot/go_modules/github.co…
feuGeneA b66eb04
Bump google.golang.org/grpc from 1.65.0 to 1.66.0
dependabot[bot] 83b349a
Bump github.com/onsi/gomega from 1.34.1 to 1.34.2
dependabot[bot] b43c59b
Merge pull request #464 from ava-labs/dependabot/go_modules/github.co…
geoff-vball f456d55
Merge branch 'main' into dependabot/go_modules/google.golang.org/grpc…
geoff-vball a1dd060
Merge pull request #462 from ava-labs/dependabot/go_modules/google.go…
geoff-vball 5852f6c
Merge remote-tracking branch 'origin/main' into etna-time
iansuvak 7f9488c
Add TODO to cleanup after Etna release
iansuvak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
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" | ||
) | ||
|
@@ -42,6 +45,9 @@ const ( | |
) | ||
|
||
var ( | ||
codec = msg.Codec | ||
corethCodec = corethMsg.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,58 @@ 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()) { | ||
// Post-Etna case | ||
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 { | ||
// Pre-Etna case | ||
if sourceSubnet == constants.PrimaryNetworkID { | ||
req := corethMsg.MessageSignatureRequest{ | ||
MessageID: unsignedMessage.ID(), | ||
} | ||
return corethMsg.RequestToBytes(corethCodec, req) | ||
} else { | ||
req := msg.MessageSignatureRequest{ | ||
MessageID: unsignedMessage.ID(), | ||
} | ||
return msg.RequestToBytes(codec, req) | ||
} | ||
} | ||
} | ||
|
||
func (s *SignatureAggregator) unmarshalResponse(responseBytes []byte) (blsSignatureBuf, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we leave TODOs and create a ticket for when this logic is okay to clean up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added TODO and entered: #466 |
||
if !s.etnaTime.IsZero() && s.etnaTime.Before(time.Now()) { | ||
// Post-Etna case | ||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have liked to do
omitempty
so that tests don't write the field out when marshaling JSON here but zero time value still gets written out unless the field type is*time.Time
which seemed messier.The value that does get written out is correctly parsed by viper to be zero time value. As a result tests run the pre-Etna case unless otherwise specified.