Skip to content

Commit

Permalink
fix(x/twap): genesis issue blocking edge net set up (backport #5129) (#…
Browse files Browse the repository at this point in the history
…5133)

Co-authored-by: Roman <[email protected]>
  • Loading branch information
mergify[bot] and p0mvn authored May 9, 2023
1 parent d811bf2 commit 6ca2133
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* [#5129](https://github.com/osmosis-labs/osmosis/pull/5129) Relax twap record validation in init genesis to allow one of the spot prices to be non-zero when twap error is observed.

## v15.1.0

### Security
Expand Down
11 changes: 1 addition & 10 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,6 @@ github.com/opencontainers/runc v1.0.2/go.mod h1:aTaHFFwQXuA71CiyxOdFFIorAoemI04s
github.com/opencontainers/runc v1.1.0/go.mod h1:Tj1hFw6eFWp/o33uxGf5yF2BX5yz2Z6iptFpuvbbKqc=
github.com/opencontainers/runc v1.1.1/go.mod h1:Tj1hFw6eFWp/o33uxGf5yF2BX5yz2Z6iptFpuvbbKqc=
github.com/opencontainers/runc v1.1.2/go.mod h1:Tj1hFw6eFWp/o33uxGf5yF2BX5yz2Z6iptFpuvbbKqc=
github.com/opencontainers/runc v1.1.5/go.mod h1:1J5XiS+vdZ3wCyZybsuxXZWGrgSr8fFJHLXuG2PsnNg=
github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/runtime-spec v1.0.1/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/runtime-spec v1.0.2-0.20190207185410-29686dbc5559/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
Expand All @@ -1490,7 +1489,6 @@ github.com/openzipkin/zipkin-go v0.1.3/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTm
github.com/openzipkin/zipkin-go v0.2.5 h1:UwtQQx2pyPIgWYHRg+epgdx1/HnBQTgN3/oIYEJTQzU=
github.com/openzipkin/zipkin-go v0.2.5/go.mod h1:KpXfKdgRDnnhsxw4pNIH9Md5lyFqKUa4YDFlwRYAMyE=
github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs=
github.com/ory/dockertest/v3 v3.10.0/go.mod h1:nr57ZbRWMqfsdGdFNLHz5jjNdDb7VVFnzAeW1n5N1Lg=
github.com/otiai10/curr v1.0.0 h1:TJIWdbX0B+kpNagQrjgq8bCMrbhiuX73M2XwgtDMoOI=
github.com/otiai10/mint v1.3.1 h1:BCmzIS3n71sGfHB5NMNDB3lHYPz8fWSkCAErHed//qc=
github.com/pact-foundation/pact-go v1.0.4 h1:OYkFijGHoZAYbOIb1LWXrwKQbMMRUv1oQ89blD2Mh2Q=
Expand Down Expand Up @@ -1582,17 +1580,10 @@ go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEa
golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/mobile v0.0.0-20200801112145-973feb4309de h1:OVJ6QQUBAesB8CZijKDSsXX7xYVtUhrkY0gwMfbi4p4=
golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 h1:nt+Q6cXKz4MosCSpnbMtqiQ8Oz0pxTef2B4Vca2lvfk=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/time v0.1.0 h1:xYY+Bajn2a7VBmTM5GikTmnK8ZuX8YgnQCqZpbBNtmA=
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
gonum.org/v1/gonum v0.12.0 h1:xKuo6hzt+gMav00meVPUlXwSdoEJP46BR+wdxQEFK2o=
google.golang.org/api v0.107.0 h1:I2SlFjD8ZWabaIFOfeEDg3pf0BHJDh6iYQ1ic3Yu/UU=
Expand Down
13 changes: 6 additions & 7 deletions x/twap/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@ func (t TwapRecord) validate() error {
return errors.New("twap record time cannot be 0")
}

// if there was an error in this record, the spot prices should be 0.
// else, the the spot prices must be positive.
// if there was an error in this record, one of the spot prices should be 0.
// else, the spot prices must be positive for both spot prices.
if t.LastErrorTime.Equal(t.Time) {
if t.P0LastSpotPrice.IsNil() || !t.P0LastSpotPrice.IsZero() {
return fmt.Errorf("twap record p0 last spot price must be zero due to having an error, was (%s)", t.P0LastSpotPrice)
}
isP0LastSpotPriseZero := t.P0LastSpotPrice.IsNil() || t.P0LastSpotPrice.IsZero()
isP1LastSpotPriseZero := t.P1LastSpotPrice.IsNil() || t.P1LastSpotPrice.IsZero()

if t.P1LastSpotPrice.IsNil() || !t.P1LastSpotPrice.IsZero() {
return fmt.Errorf("twap record p1 last spot price must be zero due to having an error, was (%s)", t.P1LastSpotPrice)
if !isP0LastSpotPriseZero && !isP1LastSpotPriseZero {
return fmt.Errorf("one of twap record p0 and p1 last spot price must be zero due to having an error, was (%s, %s)", t.P0LastSpotPrice, t.P1LastSpotPrice)
}
} else {
if t.P0LastSpotPrice.IsNil() || !t.P0LastSpotPrice.IsPositive() {
Expand Down
30 changes: 26 additions & 4 deletions x/twap/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,38 @@ func TestTWAPRecord_Validate(t *testing.T) {

expectedErr: true,
},
"invalid last spot price with error": {
"one of the last spot prices is zero when last error time is not nil": {
twapRecord: func() TwapRecord {
r := baseRecord
r.LastErrorTime = r.Time
r.P0LastSpotPrice = sdk.NewDec(5) // has to be distinct to be symmetric
r.P1LastSpotPrice = sdk.ZeroDec() // need this to be 0, to test the other case on error
r.P0LastSpotPrice = sdk.NewDec(5)
r.P1LastSpotPrice = sdk.ZeroDec() // note that this one is zero due to spot price error.
return r
}(),

expectedErr: true,
expectedErr: false, // not expecting an error since one of the spot prices is zero.
},
"both of the last spot prices are zero when last error time is not nil": {
twapRecord: func() TwapRecord {
r := baseRecord
r.LastErrorTime = r.Time
r.P0LastSpotPrice = sdk.ZeroDec() // note that this one is zero due to spot price error.
r.P1LastSpotPrice = sdk.ZeroDec() // note that this one is zero due to spot price error.
return r
}(),

expectedErr: false, // not expecting an error since both of the spot prices are zero.
},
"error: both of the last spot prices non-zero when last error time is not nil": {
twapRecord: func() TwapRecord {
r := baseRecord
r.LastErrorTime = r.Time
r.P0LastSpotPrice = sdk.NewDec(5)
r.P1LastSpotPrice = sdk.NewDecWithPrec(2, 1)
return r
}(),

expectedErr: true, // expecting an error since both of the spot prices are non-zero.
},
"invalid p0 last spot price: nil": {
twapRecord: func() TwapRecord {
Expand Down

0 comments on commit 6ca2133

Please sign in to comment.