@@ -57,17 +57,28 @@ func NewPriceOracleVoteExtHandler(logger log.Logger, valStore baseapp.ValidatorS
5757func (h * PriceOracleVoteExtHandler ) ExtendVoteHandler () sdk.ExtendVoteHandler {
5858 return func (ctx sdk.Context , req * abci.RequestExtendVote ) (* abci.ResponseExtendVote , error ) {
5959
60- if ! h . config . Enable || ! voteExtensionEnabled ( ctx , req . Height ) {
60+ if req . Height < ctx . ConsensusParams (). Abci . VoteExtensionsEnableHeight {
6161 return & abci.ResponseExtendVote {}, nil
6262 }
63+
64+ h .logger .Warn ("Prepare vote extension" )
6365 // here we'd have a helper function that gets all the prices and does a weighted average
6466
67+ // var prices map[string]string
68+ // for {
69+ // prices = h.getAllVolumeWeightedPrices()
70+ // if len(prices) > 0 {
71+ // break
72+ // }
73+ // time.Sleep(time.Second * 2)
74+ // }
75+ // prices := make(map[string]string)
6576 prices := h .getAllVolumeWeightedPrices ()
6677 h .lastPriceSyncTS = req .Time .UnixMilli ()
6778
6879 headers , err := h .getBitcoinHeaders (ctx , req .Height )
6980 if err != nil {
70- //return nil, fmt.Errorf("failed to fetch bitcoin headers: %w", err)
81+ // return nil, fmt.Errorf("failed to fetch bitcoin headers: %w", err)
7182 h .logger .Error ("failed to fetch bitcoin headers" , "error" , err )
7283 }
7384 voteExt := types.OracleVoteExtension {
@@ -89,10 +100,16 @@ func (h *PriceOracleVoteExtHandler) ExtendVoteHandler() sdk.ExtendVoteHandler {
89100func (h * PriceOracleVoteExtHandler ) VerifyVoteExtensionHandler () sdk.VerifyVoteExtensionHandler {
90101 return func (ctx sdk.Context , req * abci.RequestVerifyVoteExtension ) (* abci.ResponseVerifyVoteExtension , error ) {
91102
103+ h .logger .Warn ("VerifyVoteExtensionHandler" , "height" , req .Height , "validator" , hex .EncodeToString (req .ValidatorAddress ), "extenstion" , hex .EncodeToString (req .VoteExtension ))
104+
92105 if ! voteExtensionEnabled (ctx , req .Height ) {
93106 return & abci.ResponseVerifyVoteExtension {Status : abci .ResponseVerifyVoteExtension_ACCEPT }, nil
94107 }
95108
109+ if len (req .VoteExtension ) == 0 {
110+ return & abci.ResponseVerifyVoteExtension {Status : abci .ResponseVerifyVoteExtension_REJECT }, nil
111+ }
112+
96113 validator := hex .EncodeToString (req .ValidatorAddress )
97114 h .logger .Info ("VerifyVoteExtensionHandler" , "height" , req .Height , "validator" , validator )
98115 var voteExt types.OracleVoteExtension
@@ -105,6 +122,12 @@ func (h *PriceOracleVoteExtHandler) VerifyVoteExtensionHandler() sdk.VerifyVoteE
105122 return nil , fmt .Errorf ("vote extension height does not match request height; expected: %d, got: %d" , req .Height , voteExt .Height )
106123 }
107124
125+ if len (voteExt .Prices ) == 0 {
126+ h .logger .Error ("VerifyVoteExtensionHandler" , "height" , req .Height , "validator" , validator , "Price" , len (voteExt .Prices ))
127+ return & abci.ResponseVerifyVoteExtension {Status : abci .ResponseVerifyVoteExtension_REJECT }, nil
128+ // return nil, fmt.Errorf("invalid price length %d", len(voteExt.Prices))
129+ }
130+
108131 // if len(voteExt.Prices) > 0 {
109132 // // check if a fack price is existing.
110133 // if _, ok := voteExt.Prices[types.NULL_SYMBOL]; !ok {
@@ -251,6 +274,21 @@ func (h *PriceOracleVoteExtHandler) PrepareProposal() sdk.PrepareProposalHandler
251274 return nil , errors .New ("failed to encode injected vote extension tx" )
252275 }
253276
277+ for _ , vote := range extInfo .Votes {
278+
279+ if vote .BlockIdFlag == cmtproto .BlockIDFlagCommit {
280+ var voteExt types.OracleVoteExtension
281+ if err := voteExt .Unmarshal (vote .VoteExtension ); err != nil {
282+ h .logger .Error ("failed to decode vote extension" , "err" , err , "validator" , fmt .Sprintf ("%x" , vote .Validator .Address ))
283+ return nil , err
284+ }
285+ if len (voteExt .Prices ) == 0 {
286+ h .logger .Error ("Empty Oracle Prices" )
287+ return nil , fmt .Errorf ("invalid price length: 0" )
288+ }
289+ }
290+ }
291+
254292 // Inject a "fake" tx into the proposal s.t. validators can decode, verify,
255293 // and store the canonical stake-weighted average prices and block headers.
256294 proposalTxs = append ([][]byte {bz }, proposalTxs ... )
@@ -265,6 +303,7 @@ func (h *PriceOracleVoteExtHandler) PrepareProposal() sdk.PrepareProposalHandler
265303
266304func (h * PriceOracleVoteExtHandler ) ProcessProposal () sdk.ProcessProposalHandler {
267305 return func (ctx sdk.Context , req * abci.RequestProcessProposal ) (* abci.ResponseProcessProposal , error ) {
306+
268307 if ! voteExtensionEnabled (ctx , req .Height ) {
269308 return & abci.ResponseProcessProposal {Status : abci .ResponseProcessProposal_ACCEPT }, nil
270309 }
@@ -281,7 +320,21 @@ func (h *PriceOracleVoteExtHandler) ProcessProposal() sdk.ProcessProposalHandler
281320
282321 err := baseapp .ValidateVoteExtensions (ctx , h .valStore , req .Height , ctx .ChainID (), injectedVoteExtTx )
283322 if err != nil {
284- return nil , err
323+ return & abci.ResponseProcessProposal {Status : abci .ResponseProcessProposal_REJECT }, err
324+ }
325+
326+ for _ , vote := range injectedVoteExtTx .Votes {
327+
328+ if vote .BlockIdFlag == cmtproto .BlockIDFlagCommit {
329+ var voteExt types.OracleVoteExtension
330+ if err := voteExt .Unmarshal (vote .VoteExtension ); err != nil {
331+ h .logger .Error ("failed to decode vote extension" , "err" , err , "validator" , fmt .Sprintf ("%x" , vote .Validator .Address ))
332+ return nil , err
333+ }
334+ if len (voteExt .Prices ) == 0 {
335+ return & abci.ResponseProcessProposal {Status : abci .ResponseProcessProposal_REJECT }, nil
336+ }
337+ }
285338 }
286339
287340 return & abci.ResponseProcessProposal {Status : abci .ResponseProcessProposal_ACCEPT }, nil
0 commit comments