Skip to content

Commit

Permalink
Merge pull request #10714 from vegaprotocol/release/v0.74.3
Browse files Browse the repository at this point in the history
release v0.74.3
  • Loading branch information
jeremyletang committed Feb 20, 2024
2 parents 426c611 + cad9734 commit 4c332ca
Show file tree
Hide file tree
Showing 99 changed files with 1,144 additions and 1,109 deletions.
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@

- [](https://github.com/vegaprotocol/vega/issues/xxx)

## 0.74.3

### 🛠 Improvements

- [10700](https://github.com/vegaprotocol/vega/pull/10700) - Do not use external binaries for the `IPFS` migration in the data node

### 🐛 Fixes

- [10702](https://github.com/vegaprotocol/vega/pull/10700) - Use second precision in `GetMarginIncrease()` so that perpetual product uses second precision everywhere.
- [10698](https://github.com/vegaprotocol/vega/issues/10698) - Prevent `L2` from making too many `RPC` calls.

## 0.74.2

Expand All @@ -28,20 +38,22 @@
- [10649](https://github.com/vegaprotocol/vega/issues/10649) - Ensure markets do not get stuck in liquidity auction after protocol upgrade.
- [10641](https://github.com/vegaprotocol/vega/issues/10641) - Fix panic in amend during auction for isolated margin.
- [10656](https://github.com/vegaprotocol/vega/issues/10656) - Fix funding rates bounds can be null for perpetuals.
- [10664](https://github.com/vegaprotocol/vega/issues/10664) - Fix isolated margin handling of submit/amend to get rid of trying to restore the state of the order book.
- [10664](https://github.com/vegaprotocol/vega/issues/10664) - Fix isolated margin handling of submit/amend to get rid of trying to restore the state of the order book.
- [10661](https://github.com/vegaprotocol/vega/issues/10661) - Fix isolated margin handling of submit/amend to get rid of trying to restore the state of the order book.
- [10660](https://github.com/vegaprotocol/vega/issues/10660) - Fix isolated margin handling of submit/amend to get rid of trying to restore the state of the order book.
- [10601](https://github.com/vegaprotocol/vega/issues/10601) - Fix epoch by block height API is slow.
- [10299](https://github.com/vegaprotocol/vega/issues/10299) - Fix rewards transfers filter.
- [10666](https://github.com/vegaprotocol/vega/issues/10666) - Fix game API is slow.
- [10673](https://github.com/vegaprotocol/vega/issues/10673) - Fix error handling for isolated margin when insufficient funds.
- [10673](https://github.com/vegaprotocol/vega/issues/10673) - Fix error handling for isolated margin when insufficient funds.
- [10677](https://github.com/vegaprotocol/vega/issues/10677) - Fix validation of market proposer bonus to allow specifying/not specifying asset for metric for market proposer.
- [10669](https://github.com/vegaprotocol/vega/issues/10669) - Fix fees handling for spots in governance auction
- [10683](https://github.com/vegaprotocol/vega/issues/10683) - Fix GraphQL does not correctly marshal transfers status in filter.
- [10685](https://github.com/vegaprotocol/vega/issues/10685) - Fix list transfers returns too much data..
- [10691](https://github.com/vegaprotocol/vega/issues/10691) - Fix team stats include rewards from individual games
- [10647](https://github.com/vegaprotocol/vega/issues/10647) Add filter by game ID to transfers API.
- [10649](https://github.com/vegaprotocol/vega/issues/10649) - Ensure markets do not get stuck in liquidity auction after protocol upgrade.
- [10696](https://github.com/vegaprotocol/vega/issues/10696) - Fix position updates to undo positions changes on isolated margin failure.
- [10712](https://github.com/vegaprotocol/vega/issues/10712) - Fix the unit of auction extension and leave check auction early if governance auction has been extended.


## 0.74.1
Expand Down
44 changes: 31 additions & 13 deletions core/datasource/external/ethcall/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"reflect"
"strconv"
"sync"
"sync/atomic"
"time"

"code.vegaprotocol.io/vega/core/datasource"
Expand Down Expand Up @@ -76,7 +77,8 @@ type Engine struct {
poller *poller
mu sync.Mutex

chainID uint64
chainID atomic.Uint64
blockInterval atomic.Uint64
}

func NewEngine(log *logging.Logger, cfg Config, isValidator bool, client EthReaderCaller, forwarder Forwarder) *Engine {
Expand All @@ -89,12 +91,22 @@ func NewEngine(log *logging.Logger, cfg Config, isValidator bool, client EthRead
calls: make(map[string]Call),
poller: newPoller(cfg.PollEvery.Get()),
}

// default to 1 block interval
e.blockInterval.Store(1)

return e
}

// EnsureChainID tells the engine which chainID it should be related to, and it confirms this against the its client.
func (e *Engine) EnsureChainID(chainID string, confirmWithClient bool) {
e.chainID, _ = strconv.ParseUint(chainID, 10, 64)
func (e *Engine) EnsureChainID(chainID string, blockInterval uint64, confirmWithClient bool) {
chainIDU, _ := strconv.ParseUint(chainID, 10, 64)
e.chainID.Store(chainIDU)
e.blockInterval.Store(blockInterval)
// cover backward compatibility for L2
if e.blockInterval.Load() == 0 {
e.blockInterval.Store(1)
}

// if the node is a validator, we now check the chainID against the chain the client is connected to.
if confirmWithClient {
Expand All @@ -103,10 +115,10 @@ func (e *Engine) EnsureChainID(chainID string, confirmWithClient bool) {
log.Panic("could not load chain ID", logging.Error(err))
}

if cid.Uint64() != e.chainID {
if cid.Uint64() != e.chainID.Load() {
log.Panic("chain ID mismatch between ethCall engine and EVM client",
logging.Uint64("client-chain-id", cid.Uint64()),
logging.Uint64("engine-chain-id", e.chainID),
logging.Uint64("engine-chain-id", e.chainID.Load()),
)
}
}
Expand All @@ -121,7 +133,7 @@ func (e *Engine) Start() {
defer cancelEthereumQueries()

e.cancelEthereumQueries = cancelEthereumQueries
e.log.Info("Starting ethereum contract call polling engine", logging.Uint64("chain-id", e.chainID))
e.log.Info("Starting ethereum contract call polling engine", logging.Uint64("chain-id", e.chainID.Load()))

e.poller.Loop(func() {
e.Poll(ctx, time.Now())
Expand Down Expand Up @@ -241,7 +253,7 @@ func (e *Engine) OnSpecActivated(ctx context.Context, spec datasource.Spec) erro

// here ensure we are on the engine with the right network ID
// not an error, just return
if e.chainID != d.SourceChainID {
if e.chainID.Load() != d.SourceChainID {
return nil
}

Expand Down Expand Up @@ -274,7 +286,7 @@ func (e *Engine) Poll(ctx context.Context, wallTime time.Time) {
}

e.log.Info("tick",
logging.Uint64("chainID", e.chainID),
logging.Uint64("chainID", e.chainID.Load()),
logging.Time("wallTime", wallTime),
logging.BigInt("ethBlock", lastEthBlock.Number),
logging.Time("ethTime", time.Unix(int64(lastEthBlock.Time), 0)))
Expand All @@ -286,10 +298,16 @@ func (e *Engine) Poll(ctx context.Context, wallTime time.Time) {

// Go through an eth blocks one at a time until we get to the most recent one
for prevEthBlock := e.prevEthBlock; prevEthBlock.NumberU64() < lastEthBlock.Number.Uint64(); prevEthBlock = e.prevEthBlock {
nextBlockNum := big.NewInt(0).SetUint64(prevEthBlock.NumberU64() + 1)
nextBlockNum := big.NewInt(0).SetUint64(prevEthBlock.NumberU64() + e.blockInterval.Load())
nextEthBlock, err := e.client.HeaderByNumber(ctx, nextBlockNum)
if err != nil {
e.log.Error("failed to get next block header", logging.Error(err))
e.log.Error("failed to get next block header",
logging.Error(err),
logging.Uint64("chain-id", e.chainID.Load()),
logging.Uint64("prev-block", prevEthBlock.NumberU64()),
logging.Uint64("last-block", lastEthBlock.Number.Uint64()),
logging.Uint64("expect-next-block", nextBlockNum.Uint64()),
)
return
}

Expand All @@ -298,14 +316,14 @@ func (e *Engine) Poll(ctx context.Context, wallTime time.Time) {
if call.triggered(prevEthBlock, nextEthBlockIsh) {
res, err := call.Call(ctx, e.client, nextEthBlock.Number.Uint64())
if err != nil {
e.log.Error("failed to call contract", logging.Error(err), logging.Uint64("chain-id", e.chainID))
event := makeErrorChainEvent(err.Error(), specID, nextEthBlockIsh, e.chainID)
e.log.Error("failed to call contract", logging.Error(err), logging.Uint64("chain-id", e.chainID.Load()))
event := makeErrorChainEvent(err.Error(), specID, nextEthBlockIsh, e.chainID.Load())
e.forwarder.ForwardFromSelf(event)
continue
}

if res.PassesFilters {
event := makeChainEvent(res, specID, nextEthBlockIsh, e.chainID)
event := makeChainEvent(res, specID, nextEthBlockIsh, e.chainID.Load())
e.forwarder.ForwardFromSelf(event)
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/datasource/spec/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (e *Engine) sendNewSpecSubscription(ctx context.Context, update updatedSubs
proto.Spec.CreatedAt = update.specActivatedAt.UnixNano()
proto.Spec.Status = vegapb.DataSourceSpec_STATUS_ACTIVE

if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.13") {
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.14") {
def := update.spec.GetDefinition()
switch def.DataSourceType.(type) {
case ethcallcommon.Spec:
Expand Down
2 changes: 1 addition & 1 deletion core/evtforward/forwarder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func getTestChainEvent(txid string) *commandspb.ChainEvent {

func TestMigrationTo74(t *testing.T) {
evtFwd := getTestEvtFwd(t)
ctx := vgcontext.WithSnapshotInfo(context.Background(), "v0.73.13", true)
ctx := vgcontext.WithSnapshotInfo(context.Background(), "v0.73.14", true)
evtFwd.top.EXPECT().AllNodeIDs().AnyTimes().Return(testAllPubKeys)

hashes := []string{
Expand Down
2 changes: 1 addition & 1 deletion core/evtforward/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (f *Forwarder) restore(ctx context.Context, p *types.PayloadEventForwarder)
}

// upgrading from 73.12, we need to load previous snapshot format
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.13") {
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.14") {
// add at 0 time, so it's always way in the past.
bucket := &ackedEvtBucket{
ts: 0,
Expand Down
1 change: 1 addition & 0 deletions core/execution/common/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type TimeService interface {
type Broker interface {
Send(event events.Event)
SendBatch(events []events.Event)
Stage(event events.Event)
}

type StateVarEngine interface {
Expand Down
2 changes: 1 addition & 1 deletion core/execution/engine_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (e *Engine) restoreSpotMarket(ctx context.Context, em *types.ExecSpotMarket
func (e *Engine) restoreMarket(ctx context.Context, em *types.ExecMarket) (*future.Market, error) {
marketConfig := em.Market
// ensure the default chain ID is set, can be removed after protocol upgrade
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.13") {
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.14") {
e.ensureChainIDSet(marketConfig)
}

Expand Down
3 changes: 2 additions & 1 deletion core/execution/future/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ func (m *Market) checkAuction(ctx context.Context, now time.Time, idgen common.I

if m.mkt.State == types.MarketStateSuspendedViaGovernance {
if endTS := m.as.ExpiresAt(); endTS != nil && endTS.Before(now) {
m.as.ExtendAuctionSuspension(types.AuctionDuration{Duration: int64(m.minDuration)})
m.as.ExtendAuctionSuspension(types.AuctionDuration{Duration: int64(m.minDuration.Seconds())})
return
}
}

Expand Down
4 changes: 3 additions & 1 deletion core/execution/future/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ func (m *Market) UpdateMarketState(ctx context.Context, changes *types.MarketSta
m.mkt.State = types.MarketStateSuspendedViaGovernance
m.mkt.TradingMode = types.MarketTradingModeSuspendedViaGovernance
if m.as.InAuction() {
m.as.ExtendAuctionSuspension(types.AuctionDuration{Duration: int64(m.minDuration)})
m.as.ExtendAuctionSuspension(types.AuctionDuration{Duration: int64(m.minDuration.Seconds())})
evt := m.as.AuctionExtended(ctx, m.timeService.GetTimeNow())
if evt != nil {
m.broker.Send(evt)
Expand Down Expand Up @@ -2316,6 +2316,7 @@ func (m *Market) submitValidatedOrder(ctx context.Context, order *types.Order) (
m.log.Debug("Unable to check/add immediate trade margin for party",
logging.Order(*order), logging.Error(err))
}
_ = m.position.UnregisterOrder(ctx, order)
return nil, nil, common.ErrMarginCheckFailed
}
}
Expand Down Expand Up @@ -3683,6 +3684,7 @@ func (m *Market) amendOrder(
pos, _ := m.position.GetPositionByPartyID(amendedOrder.Party)
if err := m.updateIsolatedMarginOnOrder(ctx, pos, amendedOrder); err == risk.ErrInsufficientFundsForMarginInGeneralAccount {
m.log.Error("party has insufficient margin to cover the order change, going to cancel all orders for the party")
_ = m.position.AmendOrder(ctx, amendedOrder, existingOrder)
return nil, nil, common.ErrMarginCheckFailed
}
}
Expand Down
17 changes: 16 additions & 1 deletion core/execution/future/market_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"code.vegaprotocol.io/vega/core/assets"
"code.vegaprotocol.io/vega/core/events"
"code.vegaprotocol.io/vega/core/execution/common"
"code.vegaprotocol.io/vega/core/execution/liquidation"
"code.vegaprotocol.io/vega/core/execution/stoporders"
Expand Down Expand Up @@ -76,6 +77,14 @@ func NewMarketFromSnapshot(
}

assetDecimals := assetDetails.DecimalPlaces()

// FIXME: this is to ensure the fundingRateFactors for markets are all set to 0
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.14") {
if mkt.TradableInstrument.Instrument.GetPerps() != nil {
mkt.TradableInstrument.Instrument.GetPerps().FundingRateScalingFactor = ptr.From(num.MustDecimalFromString("0"))
}
}

tradableInstrument, err := markets.NewTradableInstrumentFromSnapshot(ctx, log, mkt.TradableInstrument, em.Market.ID,
timeService, oracleEngine, broker, em.Product, uint32(assetDecimals))
if err != nil {
Expand All @@ -84,7 +93,7 @@ func NewMarketFromSnapshot(

as := monitor.NewAuctionStateFromSnapshot(mkt, em.AuctionState)

if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.13") {
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.14") {
// protocol upgrade from v0.73.12, lets populate the new liquidity-fee-settings with a default marginal-cost method
log.Info("migrating liquidity fee settings for existing market", logging.String("mid", mkt.ID))
mkt.Fees.LiquidityFeeSettings = &types.LiquidityFeeSettings{
Expand Down Expand Up @@ -292,6 +301,12 @@ func NewMarketFromSnapshot(
}
stateVarEngine.UnregisterStateVariable(asset, mkt.ID)
}

// FIXME: We need to send the market update to the datanode to me make sure the change to the fundingRateFactor are propagated
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.14") {
broker.Stage(events.NewMarketUpdatedEvent(ctx, *market.Mkt()))
}

return market, nil
}

Expand Down
3 changes: 2 additions & 1 deletion core/execution/future/market_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func TestRestoreMarketUpgradeV0_73_2(t *testing.T) {
em.Market.Fees.LiquidityFeeSettings = nil

// and set in the context the information that says we are upgrading
ctx := vegacontext.WithSnapshotInfo(context.Background(), "v0.73.13", true)
ctx := vegacontext.WithSnapshotInfo(context.Background(), "v0.73.14", true)
snap, err := newMarketFromSnapshot(t, ctx, ctrl, em, oracleEngine)
require.NoError(t, err)
require.NotEmpty(t, snap)
Expand Down Expand Up @@ -277,6 +277,7 @@ func newMarketFromSnapshot(t *testing.T, ctx context.Context, ctrl *gomock.Contr
epochEngine.NotifyOnEpoch(marketActivityTracker.OnEpochEvent, marketActivityTracker.OnEpochRestore)

broker := bmocks.NewMockBroker(ctrl)
broker.EXPECT().Stage(gomock.Any()).AnyTimes()
broker.EXPECT().Send(gomock.Any()).AnyTimes()
timeService := mocks.NewMockTimeService(ctrl)
timeService.EXPECT().GetTimeNow().AnyTimes()
Expand Down
2 changes: 1 addition & 1 deletion core/execution/spot/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (m *Market) checkAuction(ctx context.Context, now time.Time, idgen common.I

if m.mkt.State == types.MarketStateSuspendedViaGovernance {
if endTS := m.as.ExpiresAt(); endTS != nil && endTS.Before(now) {
m.as.ExtendAuctionSuspension(types.AuctionDuration{Duration: int64(m.minDuration)})
m.as.ExtendAuctionSuspension(types.AuctionDuration{Duration: int64(m.minDuration.Seconds())})
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/execution/spot/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func (m *Market) UpdateMarketState(ctx context.Context, changes *types.MarketSta
m.mkt.State = types.MarketStateSuspendedViaGovernance
m.mkt.TradingMode = types.MarketTradingModeSuspendedViaGovernance
if m.as.InAuction() {
m.as.ExtendAuctionSuspension(types.AuctionDuration{Duration: int64(m.minDuration)})
m.as.ExtendAuctionSuspension(types.AuctionDuration{Duration: int64(m.minDuration.Seconds())})
evt := m.as.AuctionExtended(ctx, m.timeService.GetTimeNow())
if evt != nil {
m.broker.Send(evt)
Expand Down
12 changes: 6 additions & 6 deletions core/governance/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (e *Engine) restoreActiveProposals(ctx context.Context, active *types.Gover
vevts := []events.Event{}
e.log.Debug("restoring active proposals snapshot", logging.Int("nproposals", len(active.Proposals)))
for _, p := range active.Proposals {
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.13") {
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.14") {
e.ensureChainIDSet(p.Proposal)
}
pp := &proposal{
Expand All @@ -265,7 +265,7 @@ func (e *Engine) restoreActiveProposals(ctx context.Context, active *types.Gover
invalidVotes: votesAsMap(p.Invalid),
}

if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.13") {
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.14") {
if nm := pp.Proposal.Terms.GetNewMarket(); nm != nil {
e.log.Info("migrating liquidity fee settings for new market proposal", logging.String("pid", pp.ID))
nm.Changes.LiquidityFeeSettings = &types.LiquidityFeeSettings{
Expand All @@ -279,7 +279,7 @@ func (e *Engine) restoreActiveProposals(ctx context.Context, active *types.Gover
}
}
}
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.13") {
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.14") {
if pp.Terms.IsNewMarket() {
pp.Terms.GetNewMarket().Changes.MarkPriceConfiguration = defaultMarkPriceConfig.DeepClone()
}
Expand Down Expand Up @@ -324,7 +324,7 @@ func (e *Engine) restoreBatchActiveProposals(ctx context.Context, active *types.
e.log.Debug("restoring active proposals snapshot", logging.Int("nproposals", len(active.BatchProposals)))
for _, bpp := range active.BatchProposals {
bpt := types.BatchProposalFromSnapshotProto(bpp.BatchProposal.Proposal, bpp.Proposals)
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.13") {
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.14") {
e.ensureChainIDSet(bpt.Proposals...)
}
bp := &batchProposal{
Expand All @@ -336,7 +336,7 @@ func (e *Engine) restoreBatchActiveProposals(ctx context.Context, active *types.

evts = append(evts, events.NewProposalEventFromProto(ctx, bp.BatchProposal.ToProto()))
for _, p := range bp.BatchProposal.Proposals {
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.13") {
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.14") {
if p.Terms.IsNewMarket() {
p.Terms.GetNewMarket().Changes.MarkPriceConfiguration = defaultMarkPriceConfig.DeepClone()
}
Expand Down Expand Up @@ -380,7 +380,7 @@ func (e *Engine) restoreEnactedProposals(ctx context.Context, enacted *types.Gov
vevts := []events.Event{}
e.log.Debug("restoring enacted proposals snapshot", logging.Int("nproposals", len(enacted.Proposals)))
for _, p := range enacted.Proposals {
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.13") {
if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.14") {
e.ensureChainIDSet(p.Proposal)
}
pp := &proposal{
Expand Down
2 changes: 1 addition & 1 deletion core/netparams/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func defaultNetParams() map[string]value {
MustUpdate("{\"network_id\": \"XXX\", \"chain_id\": \"XXX\", \"collateral_bridge_contract\": { \"address\": \"0xXXX\" }, \"confirmations\": 3, \"staking_bridge_contract\": { \"address\": \"0xXXX\", \"deployment_block_height\": 0}, \"token_vesting_contract\": { \"address\": \"0xXXX\", \"deployment_block_height\": 0 }, \"multisig_control_contract\": { \"address\": \"0xXXX\", \"deployment_block_height\": 0 }}"),
BlockchainsEthereumL2Configs: NewJSON(&proto.EthereumL2Configs{}, types.CheckUntypedEthereumL2Configs).Mutable(true).
MustUpdate(
`{"configs":[{"network_id":"100","chain_id":"100","confirmations":3,"name":"Gnosis Chain"}, {"network_id":"42161","chain_id":"42161","confirmations":3,"name":"Arbitrum One"}]}`,
`{"configs":[{"network_id":"100","chain_id":"100","confirmations":3,"name":"Gnosis Chain", "block_interval": 3}, {"network_id":"42161","chain_id":"42161","confirmations":3,"name":"Arbitrum One", "block_interval": 50}]}`,
),

ValidatorsEpochLength: NewDuration(gte1s, lte255h).Mutable(true).MustUpdate("24h0m0s"),
Expand Down
2 changes: 2 additions & 0 deletions core/products/perpetual.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,8 @@ func (p *Perpetual) calculateInterestTerm(externalTWAP, internalTWAP *num.Uint,
// GetMarginIncrease returns the estimated extra margin required to account for the next funding payment
// for a party with a position of +1.
func (p *Perpetual) GetMarginIncrease(t int64) num.Decimal {
t = time.Unix(0, t).Truncate(time.Second).UnixNano()

// if we have no data, or the funding factor is zero, then the margin increase will always be zero
if !p.haveDataBeforeGivenTime(t) || p.p.MarginFundingFactor.IsZero() {
return num.DecimalZero()
Expand Down
Loading

0 comments on commit 4c332ca

Please sign in to comment.