Closed cdummett closed 7 months ago
this is an artefact of how the core works. Market updates are send at the end of onTick() which happens on beginBlock, before any other transactions are processed. So what would happen if the market is switching to/from an auction is that we'd publish the market data on block x, e.g. 7232 and then at the beginning on block 7233, we'd publish the market data for it before processing any other transaction. I don't think it's ideal, but it's how it's always been and it definitely doesn't represent an inconsistent state. To prove this is the case I moved the code that emits the market data event from beginBlock to endBlock, which I could nicely without changing the block hash, I'm getting consistent state for the market see below:
market update with state monitoring auction and market suspended:
{
"id": "7232-13",
"block": "6604C1A89F29BD644228DB7A78B039AB944746B7DDC256C927B35B3E81347BC1",
"type": 26,
"market_updated": {
"id": "5ae381e52dd30fb3e2cf3afe4eb971b9834bf46b2b69099f390011450776e430",
"tradable_instrument": {
"instrument": {
"code": "ETH/USDT-PERP",
"name": "Ether / Tether USD (Perpetual)",
"metadata": {
"tags": [
"base:ETH",
"quote:USDT",
"oracle:pyth",
"oracleChain:gnosis",
"class:fx/crypto",
"perpetual",
"sector:defi",
"enactment:2023-11-19T02:00:00Z"
]
},
"perpetual": {
"settlement_asset": "308fccbb0268bfce19f1f06d67ced93f79e286b4c75a2e680c86b6f512e9e2e9",
"quote_name": "USDT",
"margin_funding_factor": "0.9",
"interest_rate": "0.1095",
"clamp_lower_bound": "-0.0005",
"clamp_upper_bound": "0.0005",
"data_source_spec_for_settlement_schedule": {
"id": "6b363bc622b6626f8fc598ccca199fe243c4a2b4ae665c02d3cff15e9a729792",
"data": {
"internal": {
"time_trigger": {
"conditions": [
{
"operator": 3,
"value": "0"
}
],
"triggers": [
{
"initial": "1683627460",
"every": "300"
}
]
}
}
}
},
"data_source_spec_for_settlement_data": {
"id": "dc31a9d7701356c1c46f19e4927ff10e3930508db02ad2080ae44e93c38f3404",
"data": {
"external": {
"oracle": {
"signers": [
{
"pub_key": {
"key": "5f556d8d8c8d649868367195f2cd8ea8ae1432054708d569ac6edb4efcc6bf53"
}
}
],
"filters": [
{
"key": {
"name": "eth.price",
"type": 2,
"number_decimal_places": "18"
}
}
]
}
}
}
},
"data_source_spec_binding": {
"settlement_data_property": "eth.price",
"settlement_schedule_property": "vegaprotocol.builtin.timetrigger"
},
"funding_rate_scaling_factor": "1",
"funding_rate_lower_bound": "-0.001",
"funding_rate_upper_bound": "0.001"
}
},
"margin_calculator": {
"scaling_factors": {
"search_level": 1.1,
"initial_margin": 1.5,
"collateral_release": 1.7
}
},
"log_normal_risk_model": {
"risk_aversion_parameter": 0.000001,
"tau": 0.000003995,
"params": {
"sigma": 1
}
}
},
"decimal_places": "2",
"fees": {
"factors": {
"maker_fee": "0.0002",
"infrastructure_fee": "0.0005",
"liquidity_fee": "0.001"
},
"liquidity_fee_settings": {
"method": 1
}
},
"opening_auction": {
"duration": "590"
},
"price_monitoring_settings": {
"parameters": {
"triggers": [
{
"horizon": "21600",
"probability": "0.9999999",
"auction_extension": "86400"
},
{
"horizon": "4320",
"probability": "0.9999999",
"auction_extension": "3600"
},
{
"horizon": "1440",
"probability": "0.9999999",
"auction_extension": "1800"
},
{
"horizon": "360",
"probability": "0.9999999",
"auction_extension": "300"
}
]
}
},
"liquidity_monitoring_parameters": {
"target_stake_parameters": {
"time_window": "3600",
"scaling_factor": 0.05
}
},
"trading_mode": 4,
"state": 6,
"market_timestamps": {
"proposed": "1683626861000000000",
"pending": "1683626870000000000",
"open": "1683627462000000000"
},
"position_decimal_places": "3",
"linear_slippage_factor": "0.001",
"quadratic_slippage_factor": "0",
"liquidity_sla_params": {
"price_range": "0.03",
"commitment_min_time_fraction": "0.75",
"performance_hysteresis_epochs": "1",
"sla_competition_factor": "0.8"
},
"liquidation_strategy": {
"disposal_time_step": "1",
"disposal_fraction": "1",
"full_disposal_size": "10000000",
"max_fraction_consumed": "0.1"
},
"mark_price_configuration": {
"decay_weight": "1",
"decay_power": "1",
"cash_amount": "50000000",
"source_staleness_tolerance": [
"1m0s",
"1m0s",
"168h0m0s",
"168h0m0s",
"1m0s"
],
"composite_price_type": 2,
"data_sources_spec": [
{
"external": {
"oracle": {
"signers": [
{
"pub_key": {
"key": "5f556d8d8c8d649868367195f2cd8ea8ae1432054708d569ac6edb4efcc6bf53"
}
}
],
"filters": [
{
"key": {
"name": "eth.price",
"type": 2,
"number_decimal_places": "18"
}
}
]
}
}
},
{
"external": {
"oracle": {
"signers": [
{
"pub_key": {
"key": "5f556d8d8c8d649868367195f2cd8ea8ae1432054708d569ac6edb4efcc6bf53"
}
}
],
"filters": [
{
"key": {
"name": "eth.price",
"type": 2,
"number_decimal_places": "18"
}
}
]
}
}
}
],
"data_sources_spec_binding": [
{
"price_source_property": "eth.price"
},
{
"price_source_property": "eth.price"
}
]
},
"tick_size": "2"
},
"version": 1,
"chain_id": "CUSTOM",
"tx_hash": "6604C1A89F29BD644228DB7A78B039AB944746B7DDC256C927B35B3E81347BC1"
}
same block later the market data, with the same state:
{
"id": "7232-19",
"block": "6604C1A89F29BD644228DB7A78B039AB944746B7DDC256C927B35B3E81347BC1",
"type": 12,
"market_data": {
"mark_price": "369077",
"best_bid_price": "0",
"best_offer_price": "368600",
"best_offer_volume": "21",
"best_static_bid_price": "0",
"best_static_offer_price": "368600",
"best_static_offer_volume": "21",
"mid_price": "0",
"static_mid_price": "0",
"market": "5ae381e52dd30fb3e2cf3afe4eb971b9834bf46b2b69099f390011450776e430",
"timestamp": "1683633631000000000",
"open_interest": "6611186",
"auction_end": "1683633931000000000",
"auction_start": "1683633631000000000",
"indicative_price": "0",
"market_trading_mode": 4,
"trigger": 3,
"target_stake": "12132192824963142494917",
"supplied_stake": "1500000000000000000000000",
"price_monitoring_bounds": [
{
"min_valid_price": "350449",
"max_valid_price": "376597",
"trigger": {
"horizon": "1440",
"probability": "0.9999999",
"auction_extension": "1800"
},
"reference_price": "363295"
},
{
"min_valid_price": "341322",
"max_valid_price": "386631",
"trigger": {
"horizon": "4320",
"probability": "0.9999999",
"auction_extension": "3600"
},
"reference_price": "363295"
},
{
"min_valid_price": "315929",
"max_valid_price": "417479",
"trigger": {
"horizon": "21600",
"probability": "0.9999999",
"auction_extension": "86400"
},
"reference_price": "363295"
}
],
"market_value_proxy": "0",
"liquidity_provider_fee_share": [
{
"party": "7eec8109decdbdfd301fe55d1cfa42420663479972da72bb8ba72d3cb741cb6e",
"equity_like_share": "0.6262626262626263",
"average_entry_valuation": "2000000000000000000000000",
"average_score": "0",
"virtual_stake": "837837837837837800000000.0000000000000000"
},
{
"party": "f1a23dd0e6f3eb15e9169d4b24e01415b27f35b6dd35d05f92c3946f3cc4892b",
"equity_like_share": "0.3737373737373737",
"average_entry_valuation": "1000000000000000000000000",
"average_score": "0",
"virtual_stake": "500000000000000000000000.0000000000000000"
}
],
"market_state": 6,
"next_mark_to_market": "1683633636000000000",
"last_traded_price": "368600",
"market_growth": "0",
"product_data": {
"perpetual_data": {
"funding_payment": "-113225902918639568",
"funding_rate": "-0.0000308211879241",
"internal_twap": "3671688466037914367172",
"external_twap": "3673638511196431222352",
"seq_num": "20",
"start_time": "1683633461000000000",
"internal_composite_price": "369077",
"next_internal_composite_price_calc": "1683633636000000000",
"internal_composite_price_type": 2,
"underlying_index_price": "3698315564071345000000",
"internal_composite_price_state": {
"price_sources": [
{
"price_source": "priceFromTrades",
"price": "3683241379310344827520",
"last_updated": "1683633608000000000"
},
{
"price_source": "priceFromOrderBook",
"price": "3669230000000000000000",
"last_updated": "1683633569000000000"
},
{
"price_source": "priceFromOracle1",
"price": "3698315564071345000000",
"last_updated": "1683633608000000000"
},
{
"price_source": "priceFromOracle2",
"price": "3698315564071345000000",
"last_updated": "1683633608000000000"
},
{
"price_source": "medianPrice",
"price": "3698315564071345000000",
"last_updated": "1683633608000000000"
}
]
}
}
},
"liquidity_provider_sla": [
{
"party": "f1a23dd0e6f3eb15e9169d4b24e01415b27f35b6dd35d05f92c3946f3cc4892b",
"current_epoch_fraction_of_time_on_book": "0",
"last_epoch_fraction_of_time_on_book": "0",
"last_epoch_fee_penalty": "1",
"last_epoch_bond_penalty": "0.5",
"hysteresis_period_fee_penalties": [
"1"
],
"required_liquidity": "500000000000000000000000",
"notional_volume_buys": "0",
"notional_volume_sells": "0"
},
{
"party": "7eec8109decdbdfd301fe55d1cfa42420663479972da72bb8ba72d3cb741cb6e",
"current_epoch_fraction_of_time_on_book": "0.5871611982881598",
"last_epoch_fraction_of_time_on_book": "0.6891891891891892",
"last_epoch_fee_penalty": "1",
"last_epoch_bond_penalty": "0.1621621621621622",
"hysteresis_period_fee_penalties": [
"1"
],
"required_liquidity": "837837837837837800000000",
"notional_volume_buys": "0",
"notional_volume_sells": "1197532127595641685788052.16"
}
],
"mark_price_type": 2,
"mark_price_state": {
"price_sources": [
{
"price_source": "priceFromTrades",
"price": "3683241379310344827520",
"last_updated": "1683633608000000000"
},
{
"price_source": "priceFromOrderBook",
"price": "3669230000000000000000",
"last_updated": "1683633569000000000"
},
{
"price_source": "priceFromOracle1",
"price": "3698315564071345000000",
"last_updated": "1683633608000000000"
},
{
"price_source": "priceFromOracle2",
"price": "3698315564071345000000",
"last_updated": "1683633608000000000"
},
{
"price_source": "medianPrice",
"price": "3698315564071345000000",
"last_updated": "1683633608000000000"
}
]
}
},
"version": 1,
"chain_id": "CUSTOM",
"tx_hash": "6604C1A89F29BD644228DB7A78B039AB944746B7DDC256C927B35B3E81347BC1"
}
Awesome, thanks for looking into it @ze97286. In that case if the next block this always resolves itself then I'm happy to close this and then disable the check in market-sim 👍
Problem encountered
The
ListMarkets
andGetLatestMarketData
APIs each report the market state and trading mode. Console raised issue where APIs were reporting conflicting information.A check was added to market-sim fuzzing tests to capture this inconsistency.
Two CI runs have now captured the issue, replaying the replay file shows the APIs reporting inconsistent data despite calls being made at the same block height.
[2024-03-26T23:44:44.678Z] 2024-03-26 23:44:44,377 - vega_sim.service - INFO - Request to GetLatestMarketData made at datanode block_height=1865.
[2024-03-26T23:44:51.202Z] 2024-03-26 23:44:50,377 - vega_sim.service - WARNING - Market fcc830, market API says state STATE_SUSPENDED but market data API says STATE_ACTIVE.
{ "data": { "marketsConnection": { "edges": [ { "node": { "id": "fcc8308ee675ffeb1255206610b7fb906fddb1a05a5065f1cb8a4bd320f71d18", "state": "STATE_SUSPENDED", "tradingMode": "TRADING_MODE_MONITORING_AUCTION", "data": { "marketState": "STATE_ACTIVE", "marketTradingMode": "TRADING_MODE_CONTINUOUS" } } } ] } } }
[2024-03-27T00:13:13.063Z] 2024-03-27 00:13:12,500 - vega_sim.service - INFO - Request to ListMarkets made at datanode block_height=7232.
[2024-03-27T00:13:13.063Z] 2024-03-27 00:13:12,500 - vega_sim.service - INFO - Request to GetLatestMarketData made at datanode block_height=7232.
[2024-03-27T00:13:19.596Z] 2024-03-27 00:13:18,500 - vega_sim.service - WARNING - Market 5ae381, market API says state STATE_SUSPENDED but market data API says STATE_ACTIVE
{ "data": { "marketsConnection": { "edges": [ { "node": { "id": "5ae381e52dd30fb3e2cf3afe4eb971b9834bf46b2b69099f390011450776e430", "state": "STATE_SUSPENDED", "tradingMode": "TRADING_MODE_MONITORING_AUCTION", "data": { "marketState": "STATE_ACTIVE", "marketTradingMode": "TRADING_MODE_CONTINUOUS" } } } ] } } }
Software version
d3a35a22f37306b84db77bd9853cd5ac8e82cdee
Failing test
vega-market-sim fuzz test
Jenkins run
https://jenkins.vega.rocks/blue/organizations/jenkins/common%2Fvega-market-sim-reinforcement/detail/vega-market-sim-reinforcement/402/pipeline
Configuration used
Relevant log output