From f046f09c09f626478e458b72f4d38ead878f1974 Mon Sep 17 00:00:00 2001 From: wjrjerome Date: Fri, 22 Nov 2024 01:10:19 +1100 Subject: [PATCH 1/4] fix: sanitise event of double quotes before processing --- go.mod | 6 +++--- go.sum | 12 ++++++------ internal/services/events.go | 30 +++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 67b6eff..f6fd370 100644 --- a/go.mod +++ b/go.mod @@ -4,14 +4,14 @@ go 1.23.1 require ( github.com/avast/retry-go/v4 v4.5.1 - github.com/babylonlabs-io/babylon v0.16.1 + github.com/babylonlabs-io/babylon v0.17.0 github.com/babylonlabs-io/staking-queue-client v0.4.1 github.com/btcsuite/btcd v0.24.3-0.20241011125836-24eb815168f4 github.com/btcsuite/btcd/btcec/v2 v2.3.4 github.com/btcsuite/btcd/btcutil v1.1.6 github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 github.com/btcsuite/btcwallet v0.16.10-0.20230804184612-07be54bc22cf - github.com/cometbft/cometbft v0.38.14 + github.com/cometbft/cometbft v0.38.15 github.com/cosmos/cosmos-sdk v0.50.9 github.com/cosmos/gogoproto v1.7.0 github.com/go-chi/chi/v5 v5.1.0 @@ -31,7 +31,7 @@ require ( cosmossdk.io/depinject v1.0.0 // indirect cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/log v1.4.1 // indirect - cosmossdk.io/math v1.3.0 // indirect + cosmossdk.io/math v1.4.0 // indirect cosmossdk.io/store v1.1.0 // indirect cosmossdk.io/x/feegrant v0.1.1 // indirect cosmossdk.io/x/tx v0.13.4 // indirect diff --git a/go.sum b/go.sum index 48156c0..4700064 100644 --- a/go.sum +++ b/go.sum @@ -196,8 +196,8 @@ cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U= cosmossdk.io/log v1.4.1 h1:wKdjfDRbDyZRuWa8M+9nuvpVYxrEOwbD/CA8hvhU8QM= cosmossdk.io/log v1.4.1/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU= -cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= -cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= +cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ= +cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk= cosmossdk.io/store v1.1.0 h1:LnKwgYMc9BInn9PhpTFEQVbL9UK475G2H911CGGnWHk= cosmossdk.io/store v1.1.0/go.mod h1:oZfW/4Fc/zYqu3JmQcQdUJ3fqu5vnYTn3LZFFy8P8ng= cosmossdk.io/x/circuit v0.1.1 h1:KPJCnLChWrxD4jLwUiuQaf5mFD/1m7Omyo7oooefBVQ= @@ -280,8 +280,8 @@ github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX github.com/aws/aws-sdk-go v1.44.312 h1:llrElfzeqG/YOLFFKjg1xNpZCFJ2xraIi3PqSuP+95k= github.com/aws/aws-sdk-go v1.44.312/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= -github.com/babylonlabs-io/babylon v0.16.1 h1:IWKMzHwmwt2O0U+wiOeS2bEeR/T9T6/W5xkS4kj5GiU= -github.com/babylonlabs-io/babylon v0.16.1/go.mod h1:wEbfZ6NS/mDRP1ina17WB/4oNtpkFL9Z97bp8Ar6okQ= +github.com/babylonlabs-io/babylon v0.17.0 h1:jUNnfOAK3P0MOlyNDErTKoB2/q6kMNIYM2tM//8ZUBc= +github.com/babylonlabs-io/babylon v0.17.0/go.mod h1:sT+KG2U+M0tDMNZZ2L5CwlXX0OpagGEs56BiWXqaZFw= github.com/babylonlabs-io/staking-queue-client v0.4.1 h1:AW+jtrNxZYN/isRx+njqjHbUU9CzhF42Ke6roK+0N3I= github.com/babylonlabs-io/staking-queue-client v0.4.1/go.mod h1:n3fr3c+9LNiJlyETmcrVk94Zn76rAADhGZKxX+rVf+Q= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= @@ -399,8 +399,8 @@ github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZ github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= -github.com/cometbft/cometbft v0.38.14 h1:ketYsx8uNLSm32GAMbm98SCSNTQ7Ek7VoZonSto+F/A= -github.com/cometbft/cometbft v0.38.14/go.mod h1:xdfvFic9BHPd/MXJZVRH79XK0iLLOkiMw3ynYNhuulk= +github.com/cometbft/cometbft v0.38.15 h1:5veFd8k1uXM27PBg9sMO3hAfRJ3vbh4OmmLf6cVrqXg= +github.com/cometbft/cometbft v0.38.15/go.mod h1:+wh6ap6xctVG+JOHwbl8pPKZ0GeqdPYqISu7F4b43cQ= github.com/cometbft/cometbft-db v0.15.0 h1:VLtsRt8udD4jHCyjvrsTBpgz83qne5hnL245AcPJVRk= github.com/cometbft/cometbft-db v0.15.0/go.mod h1:EBrFs1GDRiTqrWXYi4v90Awf/gcdD5ExzdPbg4X8+mk= github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= diff --git a/internal/services/events.go b/internal/services/events.go index 97240bf..a2c50c9 100644 --- a/internal/services/events.go +++ b/internal/services/events.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net/http" + "strings" "time" "github.com/babylonlabs-io/babylon-staking-indexer/internal/types" @@ -124,8 +125,11 @@ func parseEvent[T proto.Message]( ) } + // Sanitize the event attributes before parsing + sanitizedEvent := sanitizeEvent(event) + // Use the SDK's ParseTypedEvent function - protoMsg, err := sdk.ParseTypedEvent(event) + protoMsg, err := sdk.ParseTypedEvent(sanitizedEvent) if err != nil { log.Debug().Interface("raw_event", event).Msg("Raw event data") return result, types.NewError( @@ -390,3 +394,27 @@ func (s *Service) validateSlashedFinalityProviderEvent(ctx context.Context, even return true, nil } + +func sanitizeEvent(event abcitypes.Event) abcitypes.Event { + sanitizedAttrs := make([]abcitypes.EventAttribute, len(event.Attributes)) + for i, attr := range event.Attributes { + // Remove any extra quotes and ensure proper JSON formatting + value := strings.Trim(attr.Value, "\"") + // If the value isn't already a JSON value (object, array, or quoted string), + // wrap it in quotes + if !strings.HasPrefix(value, "{") && !strings.HasPrefix(value, "[") { + value = fmt.Sprintf("\"%s\"", value) + } + + sanitizedAttrs[i] = abcitypes.EventAttribute{ + Key: attr.Key, + Value: value, + Index: attr.Index, + } + } + + return abcitypes.Event{ + Type: event.Type, + Attributes: sanitizedAttrs, + } +} From e28f9704774b5717ed8999a02699583666562e6b Mon Sep 17 00:00:00 2001 From: Gurjot Date: Fri, 22 Nov 2024 00:22:01 +0530 Subject: [PATCH 2/4] fix gomod --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f6fd370..9636f30 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( github.com/avast/retry-go/v4 v4.5.1 - github.com/babylonlabs-io/babylon v0.17.0 + github.com/babylonlabs-io/babylon v0.16.1 github.com/babylonlabs-io/staking-queue-client v0.4.1 github.com/btcsuite/btcd v0.24.3-0.20241011125836-24eb815168f4 github.com/btcsuite/btcd/btcec/v2 v2.3.4 diff --git a/go.sum b/go.sum index 4700064..9670494 100644 --- a/go.sum +++ b/go.sum @@ -280,8 +280,8 @@ github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX github.com/aws/aws-sdk-go v1.44.312 h1:llrElfzeqG/YOLFFKjg1xNpZCFJ2xraIi3PqSuP+95k= github.com/aws/aws-sdk-go v1.44.312/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= -github.com/babylonlabs-io/babylon v0.17.0 h1:jUNnfOAK3P0MOlyNDErTKoB2/q6kMNIYM2tM//8ZUBc= -github.com/babylonlabs-io/babylon v0.17.0/go.mod h1:sT+KG2U+M0tDMNZZ2L5CwlXX0OpagGEs56BiWXqaZFw= +github.com/babylonlabs-io/babylon v0.16.1 h1:IWKMzHwmwt2O0U+wiOeS2bEeR/T9T6/W5xkS4kj5GiU= +github.com/babylonlabs-io/babylon v0.16.1/go.mod h1:wEbfZ6NS/mDRP1ina17WB/4oNtpkFL9Z97bp8Ar6okQ= github.com/babylonlabs-io/staking-queue-client v0.4.1 h1:AW+jtrNxZYN/isRx+njqjHbUU9CzhF42Ke6roK+0N3I= github.com/babylonlabs-io/staking-queue-client v0.4.1/go.mod h1:n3fr3c+9LNiJlyETmcrVk94Zn76rAADhGZKxX+rVf+Q= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= From c7e7d64bbca8c61d2a7867ae7b968a0100ce5461 Mon Sep 17 00:00:00 2001 From: Gurjot Date: Fri, 22 Nov 2024 00:23:01 +0530 Subject: [PATCH 3/4] fix gomod --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 9636f30..67b6eff 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/btcsuite/btcd/btcutil v1.1.6 github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 github.com/btcsuite/btcwallet v0.16.10-0.20230804184612-07be54bc22cf - github.com/cometbft/cometbft v0.38.15 + github.com/cometbft/cometbft v0.38.14 github.com/cosmos/cosmos-sdk v0.50.9 github.com/cosmos/gogoproto v1.7.0 github.com/go-chi/chi/v5 v5.1.0 @@ -31,7 +31,7 @@ require ( cosmossdk.io/depinject v1.0.0 // indirect cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/log v1.4.1 // indirect - cosmossdk.io/math v1.4.0 // indirect + cosmossdk.io/math v1.3.0 // indirect cosmossdk.io/store v1.1.0 // indirect cosmossdk.io/x/feegrant v0.1.1 // indirect cosmossdk.io/x/tx v0.13.4 // indirect diff --git a/go.sum b/go.sum index 9670494..48156c0 100644 --- a/go.sum +++ b/go.sum @@ -196,8 +196,8 @@ cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U= cosmossdk.io/log v1.4.1 h1:wKdjfDRbDyZRuWa8M+9nuvpVYxrEOwbD/CA8hvhU8QM= cosmossdk.io/log v1.4.1/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU= -cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ= -cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk= +cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= +cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/store v1.1.0 h1:LnKwgYMc9BInn9PhpTFEQVbL9UK475G2H911CGGnWHk= cosmossdk.io/store v1.1.0/go.mod h1:oZfW/4Fc/zYqu3JmQcQdUJ3fqu5vnYTn3LZFFy8P8ng= cosmossdk.io/x/circuit v0.1.1 h1:KPJCnLChWrxD4jLwUiuQaf5mFD/1m7Omyo7oooefBVQ= @@ -399,8 +399,8 @@ github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZ github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= -github.com/cometbft/cometbft v0.38.15 h1:5veFd8k1uXM27PBg9sMO3hAfRJ3vbh4OmmLf6cVrqXg= -github.com/cometbft/cometbft v0.38.15/go.mod h1:+wh6ap6xctVG+JOHwbl8pPKZ0GeqdPYqISu7F4b43cQ= +github.com/cometbft/cometbft v0.38.14 h1:ketYsx8uNLSm32GAMbm98SCSNTQ7Ek7VoZonSto+F/A= +github.com/cometbft/cometbft v0.38.14/go.mod h1:xdfvFic9BHPd/MXJZVRH79XK0iLLOkiMw3ynYNhuulk= github.com/cometbft/cometbft-db v0.15.0 h1:VLtsRt8udD4jHCyjvrsTBpgz83qne5hnL245AcPJVRk= github.com/cometbft/cometbft-db v0.15.0/go.mod h1:EBrFs1GDRiTqrWXYi4v90Awf/gcdD5ExzdPbg4X8+mk= github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= From ec845739f71799619c72ff79912b6197e8819265 Mon Sep 17 00:00:00 2001 From: Gurjot Date: Fri, 22 Nov 2024 00:35:04 +0530 Subject: [PATCH 4/4] fix todo --- internal/services/events.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/internal/services/events.go b/internal/services/events.go index a2c50c9..e1733ed 100644 --- a/internal/services/events.go +++ b/internal/services/events.go @@ -60,9 +60,7 @@ func (s *Service) processEvent( err = s.processFinalityProviderEditedEvent(ctx, bbnEvent) case EventFinalityProviderStatusChange: log.Debug().Msg("Processing finality provider status change event") - // TODO: fix error from this event - // https://github.com/babylonlabs-io/babylon-staking-indexer/issues/24 - s.processFinalityProviderStateChangeEvent(ctx, bbnEvent) + err = s.processFinalityProviderStateChangeEvent(ctx, bbnEvent) case EventBTCDelegationCreated: log.Debug().Msg("Processing new BTC delegation event") err = s.processNewBTCDelegationEvent(ctx, bbnEvent, blockHeight)