Skip to content
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

Node: Change TxHash to TxID in MessagePublication #4219

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 82 additions & 7 deletions node/hack/accountant/send_obs.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func main() {
return
}

// Don't increment the sequence number here.
if !testSubmit(ctx, logger, guardianSigner, wormchainConn, contract, "0000000000000000000000000290fb167208af455bb137780163b7b7a9a10c16", timestamp, sequence, true, "Already commited should succeed") {
return
}
Expand All @@ -82,6 +83,11 @@ func main() {
return
}

sequence += 10
if !testBigBatch(ctx, logger, guardianSigner, wormchainConn, contract, "0000000000000000000000000290fb167208af455bb137780163b7b7a9a10c16", timestamp, sequence, true, "Submit of big batch should succeed") {
return
}

logger.Info("Success! All tests passed!")
}

Expand All @@ -102,7 +108,7 @@ func testSubmit(
Payload, _ := hex.DecodeString("010000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000002d8be6bf0baa74e0a907016679cae9190e80dd0a0002000000000000000000000000c10820983f33456ce7beb3a046f5a83fa34f027d0c200000000000000000000000000000000000000000000000000000000000000000")

msg := common.MessagePublication{
TxHash: TxHash,
TxID: TxHash.Bytes(),
Timestamp: timestamp,
Nonce: uint32(0),
Sequence: sequence,
Expand Down Expand Up @@ -167,7 +173,7 @@ func testBatch(
msgs := []*common.MessagePublication{}

msg1 := common.MessagePublication{
TxHash: TxHash,
TxID: TxHash.Bytes(),
Timestamp: timestamp,
Nonce: nonce,
Sequence: sequence,
Expand All @@ -181,7 +187,7 @@ func testBatch(
nonce = nonce + 1
sequence = sequence + 1
msg2 := common.MessagePublication{
TxHash: TxHash,
TxID: TxHash.Bytes(),
Timestamp: time.Now(),
Nonce: nonce,
Sequence: sequence,
Expand Down Expand Up @@ -246,7 +252,7 @@ func testBatchWithcommitted(

logger.Info("submitting a single transfer that should work")
msg1 := common.MessagePublication{
TxHash: TxHash,
TxID: TxHash.Bytes(),
Timestamp: timestamp,
Nonce: nonce,
Sequence: sequence,
Expand All @@ -269,7 +275,7 @@ func testBatchWithcommitted(
nonce = nonce + 1
sequence = sequence + 1
msg2 := common.MessagePublication{
TxHash: TxHash,
TxID: TxHash.Bytes(),
Timestamp: time.Now(),
Nonce: nonce,
Sequence: sequence,
Expand Down Expand Up @@ -338,7 +344,7 @@ func testBatchWithDigestError(

logger.Info("submitting a single transfer that should work")
msg1 := common.MessagePublication{
TxHash: TxHash,
TxID: TxHash.Bytes(),
Timestamp: timestamp,
Nonce: nonce,
Sequence: sequence,
Expand All @@ -361,7 +367,7 @@ func testBatchWithDigestError(
nonce = nonce + 1
sequence = sequence + 1
msg2 := common.MessagePublication{
TxHash: TxHash,
TxID: TxHash.Bytes(),
Timestamp: time.Now(),
Nonce: nonce,
Sequence: sequence,
Expand Down Expand Up @@ -440,3 +446,72 @@ func submit(

return accountant.SubmitObservationsToContract(ctx, logger, guardianSigner, gsIndex, guardianIndex, wormchainConn, contract, accountant.SubmitObservationPrefix, msgs)
}

func testBigBatch(
ctx context.Context,
logger *zap.Logger,
guardianSigner guardiansigner.GuardianSigner,
wormchainConn *wormconn.ClientConn,
contract string,
emitterAddressStr string,
timestamp time.Time,
sequence uint64,
expectedResult bool,
tag string,
) bool {
EmitterAddress, _ := vaa.StringToAddress(emitterAddressStr)
TxHash := []byte("0123456789012345678901234567890123456789012345678901234567890123") // 64 bytes, the size of a Solana signature.
Payload, _ := hex.DecodeString("010000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000002d8be6bf0baa74e0a907016679cae9190e80dd0a0002000000000000000000000000c10820983f33456ce7beb3a046f5a83fa34f027d0c200000000000000000000000000000000000000000000000000000000000000000")

msgs := []*common.MessagePublication{}
for idx := 0; idx < 10; idx++ {
msg := common.MessagePublication{
TxID: TxHash,
Timestamp: timestamp,
Nonce: uint32(0),
Sequence: sequence,
EmitterChain: vaa.ChainIDEthereum,
EmitterAddress: EmitterAddress,
ConsistencyLevel: uint8(15),
Payload: Payload,
}

msgs = append(msgs, &msg)
sequence += 1
}

txResp, err := submit(ctx, logger, guardianSigner, wormchainConn, contract, msgs)
if err != nil {
logger.Error("failed to broadcast Observation request", zap.String("test", tag), zap.Error(err))
return false
}

responses, err := accountant.GetObservationResponses(txResp)
if err != nil {
logger.Error("failed to get responses", zap.Error(err))
return false
}

if len(responses) != len(msgs) {
logger.Error("number of responses does not match number of messages", zap.Int("numMsgs", len(msgs)), zap.Int("numResp", len(responses)), zap.Error(err))
return false
}

msgId := msgs[0].MessageIDString()
status, exists := responses[msgId]
if !exists {
logger.Info("test failed: did not receive an observation response for message", zap.String("test", tag), zap.String("msgId", msgId))
return false
}

committed := status.Type == "committed"

if committed != expectedResult {
logger.Info("test failed", zap.String("test", tag), zap.Uint64("seqNo", sequence), zap.Bool("committed", committed),
zap.String("response", wormchainConn.BroadcastTxResponseToString(txResp)))
return false
}

logger.Info("test of big batch succeeded", zap.String("test", tag))
return true
}
2 changes: 1 addition & 1 deletion node/hack/repair_terra/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func EventsToMessagePublications(contract string, txHash string, events []gjson.
continue
}
messagePublication := &common.MessagePublication{
TxHash: txHashValue,
TxID: txHashValue.Bytes(),
Timestamp: time.Unix(blockTimeInt, 0),
Nonce: uint32(nonceInt),
Sequence: sequenceInt,
Expand Down
18 changes: 9 additions & 9 deletions node/pkg/accountant/accountant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ func newAccountantForTest(
return acct
}

// Converts a string into a go-ethereum Hash object used as test input.
func hashFromString(str string) ethCommon.Hash { //nolint:unparam
// Converts a TxHash string into a byte array to be used as a TxID.
func hashToTxID(str string) []byte {
if (len(str) > 2) && (str[0] == '0') && (str[1] == 'x') {
str = str[2:]
}

return ethCommon.HexToHash(str)
return ethCommon.HexToHash(str).Bytes()
}

// Note this method assumes 18 decimals for the amount.
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestVaaFromUninterestingEmitter(t *testing.T) {
var payload = []byte{1, 97, 97, 97, 97, 97}

msg := common.MessagePublication{
TxHash: hashFromString("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
TxID: hashToTxID("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4064"),
Timestamp: time.Unix(int64(1654543099), 0),
Nonce: uint32(1),
Sequence: uint64(1),
Expand Down Expand Up @@ -216,7 +216,7 @@ func TestVaaForUninterestingPayloadType(t *testing.T) {
var payload = []byte{2, 97, 97, 97, 97, 97}

msg := common.MessagePublication{
TxHash: hashFromString("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
TxID: hashToTxID("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
Timestamp: time.Unix(int64(1654543099), 0),
Nonce: uint32(1),
Sequence: uint64(1),
Expand Down Expand Up @@ -251,7 +251,7 @@ func TestInterestingTransferShouldNotBeBlockedWhenNotEnforcingAccountant(t *test
)

msg := common.MessagePublication{
TxHash: hashFromString("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
TxID: hashToTxID("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
Timestamp: time.Unix(int64(1654543099), 0),
Nonce: uint32(1),
Sequence: uint64(1),
Expand Down Expand Up @@ -295,7 +295,7 @@ func TestInterestingTransferShouldBeBlockedWhenEnforcingAccountant(t *testing.T)
)

msg := common.MessagePublication{
TxHash: hashFromString("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
TxID: hashToTxID("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
Timestamp: time.Unix(int64(1654543099), 0),
Nonce: uint32(1),
Sequence: uint64(1),
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestForDeadlock(t *testing.T) {
)

msg := common.MessagePublication{
TxHash: hashFromString("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
TxID: hashToTxID("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
Timestamp: time.Unix(int64(1654543099), 0),
Nonce: uint32(1),
Sequence: uint64(1683136244),
Expand All @@ -374,7 +374,7 @@ func TestForDeadlock(t *testing.T) {
assert.Equal(t, 1, len(acct.msgChan))

msg2 := common.MessagePublication{
TxHash: hashFromString("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
TxID: hashToTxID("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
Timestamp: time.Unix(int64(1654543099), 0),
Nonce: uint32(1),
Sequence: uint64(1683136244),
Expand Down
2 changes: 1 addition & 1 deletion node/pkg/accountant/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (mo *MissingObservation) makeAuditKey() string {

// makeAuditKey creates an audit map key from a pending observation entry.
func (pe *pendingEntry) makeAuditKey() string {
return fmt.Sprintf("%d-%s", pe.msg.EmitterChain, strings.TrimPrefix(pe.msg.TxHash.String(), "0x"))
return fmt.Sprintf("%d-%s", pe.msg.EmitterChain, strings.TrimPrefix(pe.msg.TxIDString(), "0x"))
}

// audit is the runnable that executes the audit each interval.
Expand Down
10 changes: 5 additions & 5 deletions node/pkg/accountant/ntt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestNttParseMsgSuccess(t *testing.T) {
}

msg := &common.MessagePublication{
TxHash: hashFromString("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
TxID: hashToTxID("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
Timestamp: time.Unix(int64(1654543099), 0),
Nonce: uint32(42),
Sequence: uint64(123456),
Expand All @@ -77,7 +77,7 @@ func TestNttParseMsgWrongEmitterChain(t *testing.T) {
}

msg := &common.MessagePublication{
TxHash: hashFromString("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
TxID: hashToTxID("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
Timestamp: time.Unix(int64(1654543099), 0),
Nonce: uint32(42),
Sequence: uint64(123456),
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestNttParseMsgWrongEmitterAddress(t *testing.T) {
}

msg := &common.MessagePublication{
TxHash: hashFromString("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
TxID: hashToTxID("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
Timestamp: time.Unix(int64(1654543099), 0),
Nonce: uint32(42),
Sequence: uint64(123456),
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestNttParseArMsgSuccess(t *testing.T) {
require.NoError(t, err)

msg := &common.MessagePublication{
TxHash: hashFromString("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
TxID: hashToTxID("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
Timestamp: time.Unix(int64(1708575745), 0),
Nonce: uint32(0),
Sequence: uint64(259),
Expand Down Expand Up @@ -258,7 +258,7 @@ func TestNttParseArMsgUnknownArEmitter(t *testing.T) {
require.NoError(t, err)

msg := &common.MessagePublication{
TxHash: hashFromString("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
TxID: hashToTxID("0x06f541f5ecfc43407c31587aa6ac3a689e8960f36dc23c332db5510dfc6a4063"),
Timestamp: time.Unix(int64(1708575745), 0),
Nonce: uint32(0),
Sequence: uint64(259),
Expand Down
4 changes: 2 additions & 2 deletions node/pkg/accountant/submit_obs.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func SubmitObservationsToContract(
obs := make([]Observation, len(msgs))
for idx, msg := range msgs {
obs[idx] = Observation{
TxHash: msg.TxHash.Bytes(),
TxHash: msg.TxID,
Timestamp: uint32(msg.Timestamp.Unix()),
Nonce: msg.Nonce,
EmitterChain: uint16(msg.EmitterChain),
Expand All @@ -321,7 +321,7 @@ func SubmitObservationsToContract(
logger.Debug("in SubmitObservationsToContract, encoding observation",
zap.String("contract", contract),
zap.Int("idx", idx),
zap.String("txHash", msg.TxHash.String()), zap.String("encTxHash", hex.EncodeToString(obs[idx].TxHash[:])),
zap.String("txHash", msg.TxIDString()), zap.String("encTxHash", hex.EncodeToString(obs[idx].TxHash[:])),
zap.Stringer("timeStamp", msg.Timestamp), zap.Uint32("encTimestamp", obs[idx].Timestamp),
zap.Uint32("nonce", msg.Nonce), zap.Uint32("encNonce", obs[idx].Nonce),
zap.Stringer("emitterChain", msg.EmitterChain), zap.Uint16("encEmitterChain", obs[idx].EmitterChain),
Expand Down
4 changes: 1 addition & 3 deletions node/pkg/accountant/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/certusone/wormhole/node/pkg/common"
"github.com/wormhole-foundation/wormhole/sdk/vaa"

ethCommon "github.com/ethereum/go-ethereum/common"

tmAbci "github.com/tendermint/tendermint/abci/types"
tmHttp "github.com/tendermint/tendermint/rpc/client/http"
tmCoreTypes "github.com/tendermint/tendermint/rpc/core/types"
Expand Down Expand Up @@ -181,7 +179,7 @@ func (acct *Accountant) processPendingTransfer(xfer *WasmObservation, tag string
)

msg := &common.MessagePublication{
TxHash: ethCommon.BytesToHash(xfer.TxHash),
TxID: xfer.TxHash,
Timestamp: time.Unix(int64(xfer.Timestamp), 0),
Nonce: xfer.Nonce,
Sequence: xfer.Sequence,
Expand Down
2 changes: 1 addition & 1 deletion node/pkg/adminrpc/adminserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ func (s *nodePrivilegedService) InjectGovernanceVAA(ctx context.Context, req *no
vaaInjectionsTotal.Inc()

s.injectC <- &common.MessagePublication{
TxHash: ethcommon.Hash{},
TxID: ethcommon.Hash{}.Bytes(),
Timestamp: v.Timestamp,
Nonce: v.Nonce,
Sequence: v.Sequence,
Expand Down
Loading
Loading