waku2: log envelope hash and ids for all messages (#2427)

This commit is contained in:
Richard Ramos 2021-11-11 12:13:55 -04:00 committed by GitHub
parent c95c29bba5
commit 38cc695753
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 8 deletions

View File

@ -3,13 +3,14 @@ package protocol
import (
"crypto/ecdsa"
"encoding/json"
"log"
"reflect"
"github.com/golang/protobuf/proto"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol/encryption"
@ -155,6 +156,8 @@ func (m *StatusMessage) HandleApplicationMetadata() error {
m.ApplicationMetadataLayerSigPubKey = recoveredKey
// Calculate ID using the wrapped record
m.ID = MessageID(recoveredKey, m.DecryptedPayload)
log.Debug("calculated ID for envelope", "envelopeHash", hexutil.Encode(m.Hash), "messageId", hexutil.Encode(m.ID))
m.UnwrappedPayload = message.Payload
m.Type = message.Type
return nil
@ -197,7 +200,7 @@ func (m *StatusMessage) HandleApplication() error {
return m.unmarshalProtobufData(new(protobuf.SyncInstallation))
case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION_CONTACT:
log.Printf("Sync installation contact")
log.Debug("Sync installation contact")
return m.unmarshalProtobufData(new(protobuf.SyncInstallationContactV2))
case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION_PUBLIC_CHAT:
@ -268,7 +271,7 @@ func (m *StatusMessage) unmarshalProtobufData(pb proto.Message) error {
err := proto.Unmarshal(m.UnwrappedPayload, ptr)
if err != nil {
m.ParsedMessage = nil
log.Printf("[message::DecodeMessage] could not decode %T: %#x, err: %v", pb, m.Hash, err.Error())
log.Error("[message::DecodeMessage] could not decode %T: %#x, err: %v", pb, m.Hash, err.Error())
} else {
rv = reflect.ValueOf(ptr)
elem := rv.Elem()

View File

@ -39,12 +39,12 @@ func (api *API) CheckRecentHistoryForChainIDs(ctx context.Context, chainIDs []ui
// GetTransfersByAddress returns transfers for a single address
func (api *API) GetTransfersByAddress(ctx context.Context, address common.Address, toBlock, limit *hexutil.Big, fetchMore bool) ([]transfer.View, error) {
log.Debug("[WalletAPI:: GetTransfersByAddress] get transfers for an address", "address", address, "block", toBlock, "limit", limit)
log.Debug("[WalletAPI:: GetTransfersByAddress] get transfers for an address", "address")
return api.s.transferController.GetTransfersByAddress(ctx, api.s.rpcClient.UpstreamChainID, address, toBlock, limit, fetchMore)
}
func (api *API) GetTransfersByAddressAndChainID(ctx context.Context, chainID uint64, address common.Address, toBlock, limit *hexutil.Big, fetchMore bool) ([]transfer.View, error) {
log.Debug("[WalletAPI:: GetTransfersByAddressAndChainID] get transfers for an address", "address", address, "block", toBlock, "limit", limit)
log.Debug("[WalletAPI:: GetTransfersByAddressAndChainID] get transfers for an address", "address", address)
return api.s.transferController.GetTransfersByAddress(ctx, chainID, address, toBlock, limit, fetchMore)
}

View File

@ -170,7 +170,7 @@ func mapToList(m map[common.Address]struct{}) []common.Address {
}
func (c *Controller) GetTransfersByAddress(ctx context.Context, chainID uint64, address common.Address, toBlock, limit *hexutil.Big, fetchMore bool) ([]View, error) {
log.Debug("[WalletAPI:: GetTransfersByAddress] get transfers for an address", "address", address, "block", toBlock, "limit", limit)
log.Debug("[WalletAPI:: GetTransfersByAddress] get transfers for an address", "address", address)
var toBlockBN *big.Int
if toBlock != nil {
toBlockBN = toBlock.ToInt()

View File

@ -149,8 +149,7 @@ func NewReceivedMessage(env *protocol.Envelope) *ReceivedMessage {
// Hash returns the SHA3 hash of the envelope, calculating it if not yet done.
func (msg *ReceivedMessage) Hash() common.Hash {
if (msg.hash == common.Hash{}) {
envelopeHash := msg.Envelope.Hash()
msg.hash = crypto.Keccak256Hash(envelopeHash[:])
msg.hash = common.BytesToHash(msg.Envelope.Hash())
}
return msg.hash
}

View File

@ -828,6 +828,7 @@ func (w *Waku) Query(topics []common.TopicType, from uint64, to uint64, opts []s
for _, msg := range result.Messages {
envelope := wakuprotocol.NewEnvelope(msg, string(relay.DefaultWakuTopic))
w.logger.Debug("received waku2 store message", zap.Any("envelopeHash", hexutil.Encode(envelope.Hash())))
_, err = w.OnNewEnvelopes(envelope)
if err != nil {
return nil, err