vegaprotocol / vega

A Go implementation of the Vega Protocol, a protocol for creating and trading derivatives on a fully decentralised network.
https://vega.xyz
GNU Affero General Public License v3.0
37 stars 22 forks source link

[Bug]: Market does not enter continuous trading as soon as it could do #9412

Closed jgsbennett closed 1 year ago

jgsbennett commented 1 year ago

Leaving the issue below as-is for reference/context. Comments relate to that particular issue

While looking in to this issue, another sneaky bug was found. When a market is proposed, we create the market in the execution engine setting the auction state to opening auction, and initialising the auction start time to "now" (ie the block time when the proposal was submitted). When the vote closes, and the market is accepted, the actual opening auction should start, but the auction start time is never updated. This means that markets, once they passed governance, will be able to leave opening auction as soon as vega time >= proposed time + auction duration, rather than vote close time + auction duration (or enactment time). This bug was fixed in the PR referencing this issue


Problem encountered

I have noticed that markets are not as prompt leaving auctions as they could be (or used to be). In tests, the final order that is needed to cause a market to leave auction only results in the market leaving auction 4 blocks later.

Observed behaviour

Market leaves auction blocks after requirements are met

Expected behaviour

Market leaves auction as soon as requirements are met

Steps to reproduce

For instance this test: 
https://jenkins.vega.rocks/job/common/job/system-tests-wrapper/9032/artifact/test_logs/tests.matching_engine.continuous_trading_test/test_ActivePeggedOrder_GTT_GTC_GFN%5Border_param0%5D
Creates a market, then trades. Go and inspect the event files afterwards. Steps are approximately:
1: Test proposes a market
2: Test waits for market proposal to be "Enacted" (i.e: Auction period ended, but still in auction)
3: Test submits SLA
4: Test submits a whole bunch of orders, the final one of which should cause the market to leave auction.

Software version

e905eb92661d4438d39611660b8e139e0106e539

Failing test

No response

Jenkins run

https://jenkins.vega.rocks/job/common/job/system-tests-wrapper/9032/

Configuration used

No response

Relevant log output

{"id":"1372-45","block":"37BE0B8109281FFFFA0AFF37A49C79C0F86E19113E057AE636E09BF523E686B6","type":"BUS_EVENT_TYPE_PROPOSAL","proposal":{"id":"ee4cc727547c9b278878e1fd77e4f7d4071acc7ccf43dd3c53a9f5b86875fd08","reference":"4C81441F50","partyId":"1d11fc722ab67235c518e985eaa3339ad94b3fc74953b10341140270521a6733","state":"STATE_OPEN","timestamp":"1694695144310056719","terms":{"closingTimestamp":"1694695151","enactmentTimestamp":"1694695152","newMarket":{"changes":{"instrument":{"name":"Futures System-Tests Market","code":"CRYPTO:VEGA CORE SYS TEST","future":{"settlementAsset":"4c3478308c1d8156afe1bba09e07106b83dbaa23e3b849efe8584009ab808b05","quoteName":"USD","dataSourceSpecForSettlementData":{"external":{"oracle":{"signers":[{"pubKey":{"key":"1d11fc722ab67235c518e985eaa3339ad94b3fc74953b10341140270521a6733"}}],"filters":[{"key":{"name":"external.test.settlement_0D5400591E","type":"TYPE_INTEGER","numberDecimalPlaces":"3"},"conditions":[{"operator":"OPERATOR_GREATER_THAN_OR_EQUAL","value":"0"}]}]}}},"dataSourceSpecForTradingTermination":{"external":{"oracle":{"signers":[{"pubKey":{"key":"1d11fc722ab67235c518e985eaa3339ad94b3fc74953b10341140270521a6733"}}],"filters":[{"key":{"name":"external.test.termination_3F0FD43024","type":"TYPE_BOOLEAN"},"conditions":[{"operator":"OPERATOR_EQUALS","value":"True"}]}]}}},"dataSourceSpecBinding":{"settlementDataProperty":"external.test.settlement_0D5400591E","tradingTerminationProperty":"external.test.termination_3F0FD43024"}}},"decimalPlaces":"5","metadata":["asset_class:fx/crypto","product:futures"],"priceMonitoringParameters":{},"liquidityMonitoringParameters":{"targetStakeParameters":{"timeWindow":"10","scalingFactor":5},"triggeringRatio":"0"},"logNormal":{"riskAversionParameter":0.001,"tau":0.00011407711613050422,"params":{"r":0.016,"sigma":1.5}},"positionDecimalPlaces":"5","linearSlippageFactor":"0.01","quadraticSlippageFactor":"0","liquiditySlaParameters":{"priceRange":"1","commitmentMinTimeFraction":"0","performanceHysteresisEpochs":"1","slaCompetitionFactor":"1"}}}},"rationale":{"description":"Proposal submitted to enact a new Market","title":"Market Proposal"},"requiredParticipation":"0.00000015","requiredMajority":"0.66"},"version":1,"chainId":"testnet-001","txHash":"DE7A5A3B15925A8326ADC95C0CB60CA7B3E6FF98146B6B084CAE446A9509C8A9"}
{"id":"1386-46","block":"0B11901631719F9324694CD619A984C38E2AA04CE06B7A33D31D25D40FB4B118","type":"BUS_EVENT_TYPE_PROPOSAL","proposal":{"id":"ee4cc727547c9b278878e1fd77e4f7d4071acc7ccf43dd3c53a9f5b86875fd08","reference":"4C81441F50","partyId":"1d11fc722ab67235c518e985eaa3339ad94b3fc74953b10341140270521a6733","state":"STATE_PASSED","timestamp":"1694695144310056719","terms":{"closingTimestamp":"1694695151","enactmentTimestamp":"1694695152","newMarket":{"changes":{"instrument":{"name":"Futures System-Tests Market","code":"CRYPTO:VEGA CORE SYS TEST","future":{"settlementAsset":"4c3478308c1d8156afe1bba09e07106b83dbaa23e3b849efe8584009ab808b05","quoteName":"USD","dataSourceSpecForSettlementData":{"external":{"oracle":{"signers":[{"pubKey":{"key":"1d11fc722ab67235c518e985eaa3339ad94b3fc74953b10341140270521a6733"}}],"filters":[{"key":{"name":"external.test.settlement_0D5400591E","type":"TYPE_INTEGER","numberDecimalPlaces":"3"},"conditions":[{"operator":"OPERATOR_GREATER_THAN_OR_EQUAL","value":"0"}]}]}}},"dataSourceSpecForTradingTermination":{"external":{"oracle":{"signers":[{"pubKey":{"key":"1d11fc722ab67235c518e985eaa3339ad94b3fc74953b10341140270521a6733"}}],"filters":[{"key":{"name":"external.test.termination_3F0FD43024","type":"TYPE_BOOLEAN"},"conditions":[{"operator":"OPERATOR_EQUALS","value":"True"}]}]}}},"dataSourceSpecBinding":{"settlementDataProperty":"external.test.settlement_0D5400591E","tradingTerminationProperty":"external.test.termination_3F0FD43024"}}},"decimalPlaces":"5","metadata":["asset_class:fx/crypto","product:futures"],"priceMonitoringParameters":{},"liquidityMonitoringParameters":{"targetStakeParameters":{"timeWindow":"10","scalingFactor":5},"triggeringRatio":"0","auctionExtension":"1"},"logNormal":{"riskAversionParameter":0.001,"tau":0.00011407711613050422,"params":{"r":0.016,"sigma":1.5}},"positionDecimalPlaces":"5","linearSlippageFactor":"0.01","quadraticSlippageFactor":"0","liquiditySlaParameters":{"priceRange":"1","commitmentMinTimeFraction":"0","performanceHysteresisEpochs":"1","slaCompetitionFactor":"1"}}}},"rationale":{"description":"Proposal submitted to enact a new Market","title":"Market Proposal"},"requiredParticipation":"0.00000015","requiredMajority":"0.66"},"version":1,"chainId":"testnet-001","txHash":"0B11901631719F9324694CD619A984C38E2AA04CE06B7A33D31D25D40FB4B118"}
{"id":"1388-46","block":"89ECBF679E0B1477A37062439FEAFD205860ED20FBE6721A134EDBE43D78ABEA","type":"BUS_EVENT_TYPE_PROPOSAL","proposal":{"id":"ee4cc727547c9b278878e1fd77e4f7d4071acc7ccf43dd3c53a9f5b86875fd08","reference":"4C81441F50","partyId":"1d11fc722ab67235c518e985eaa3339ad94b3fc74953b10341140270521a6733","state":"STATE_ENACTED","timestamp":"1694695144310056719","terms":{"closingTimestamp":"1694695151","enactmentTimestamp":"1694695152","newMarket":{"changes":{"instrument":{"name":"Futures System-Tests Market","code":"CRYPTO:VEGA CORE SYS TEST","future":{"settlementAsset":"4c3478308c1d8156afe1bba09e07106b83dbaa23e3b849efe8584009ab808b05","quoteName":"USD","dataSourceSpecForSettlementData":{"external":{"oracle":{"signers":[{"pubKey":{"key":"1d11fc722ab67235c518e985eaa3339ad94b3fc74953b10341140270521a6733"}}],"filters":[{"key":{"name":"external.test.settlement_0D5400591E","type":"TYPE_INTEGER","numberDecimalPlaces":"3"},"conditions":[{"operator":"OPERATOR_GREATER_THAN_OR_EQUAL","value":"0"}]}]}}},"dataSourceSpecForTradingTermination":{"external":{"oracle":{"signers":[{"pubKey":{"key":"1d11fc722ab67235c518e985eaa3339ad94b3fc74953b10341140270521a6733"}}],"filters":[{"key":{"name":"external.test.termination_3F0FD43024","type":"TYPE_BOOLEAN"},"conditions":[{"operator":"OPERATOR_EQUALS","value":"True"}]}]}}},"dataSourceSpecBinding":{"settlementDataProperty":"external.test.settlement_0D5400591E","tradingTerminationProperty":"external.test.termination_3F0FD43024"}}},"decimalPlaces":"5","metadata":["asset_class:fx/crypto","product:futures"],"priceMonitoringParameters":{},"liquidityMonitoringParameters":{"targetStakeParameters":{"timeWindow":"10","scalingFactor":5},"triggeringRatio":"0","auctionExtension":"1"},"logNormal":{"riskAversionParameter":0.001,"tau":0.00011407711613050422,"params":{"r":0.016,"sigma":1.5}},"positionDecimalPlaces":"5","linearSlippageFactor":"0.01","quadraticSlippageFactor":"0","liquiditySlaParameters":{"priceRange":"1","commitmentMinTimeFraction":"0","performanceHysteresisEpochs":"1","slaCompetitionFactor":"1"}}}},"rationale":{"description":"Proposal submitted to enact a new Market","title":"Market Proposal"},"requiredParticipation":"0.00000015","requiredMajority":"0.66"},"version":1,"chainId":"testnet-001","txHash":"89ECBF679E0B1477A37062439FEAFD205860ED20FBE6721A134EDBE43D78ABEA"}

=====================

{"id":"1420-52","block":"F9AC20CD52A7A9EABC147FC3CDB0B67CC7F8AC61140C3CF2DC9B69E2325A2173","type":"BUS_EVENT_TYPE_ORDER","order":{"id":"47d8f4239050bfb4cf15bf6f4c8d8d88503e3c6704a66862a2e5aa4c30abdb73","marketId":"ee4cc727547c9b278878e1fd77e4f7d4071acc7ccf43dd3c53a9f5b86875fd08","partyId":"066b54c711991c0078f129406bbeb1eba6913b6208ebdb0d20f15c0094318827","side":"SIDE_BUY","price":"100000","size":"39050000000","remaining":"39050000000","timeInForce":"TIME_IN_FORCE_GTC","type":"TYPE_LIMIT","createdAt":"1694695171523191388","status":"STATUS_ACTIVE","reference":"test_ActivePeggedOrder_GTT_GTC_GFN[order_param0]-fd30fb76","version":"1"},"version":1,"chainId":"testnet-001","txHash":"80ED489CE115E2FEC610BDACF67832977CFCEC4C81F4011FF9DC7EAADC699AE8"}
{"id":"1420-55","block":"F9AC20CD52A7A9EABC147FC3CDB0B67CC7F8AC61140C3CF2DC9B69E2325A2173","type":"BUS_EVENT_TYPE_ORDER","order":{"id":"33bfce3c504972719f33d505182ddab674ca3670491a3ef896a9dc4998d15378","marketId":"ee4cc727547c9b278878e1fd77e4f7d4071acc7ccf43dd3c53a9f5b86875fd08","partyId":"066b54c711991c0078f129406bbeb1eba6913b6208ebdb0d20f15c0094318827","side":"SIDE_SELL","price":"1000000000","size":"1","remaining":"1","timeInForce":"TIME_IN_FORCE_GTC","type":"TYPE_LIMIT","createdAt":"1694695171523191388","status":"STATUS_ACTIVE","reference":"test_ActivePeggedOrder_GTT_GTC_GFN[order_param0]-81beb0b8","version":"1"},"version":1,"chainId":"testnet-001","txHash":"2270A6B7FA55A051C520132E459CF6386AEB32CCCB894BDCDAA96BEF21CE9FF0"}
{"id":"1424-52","block":"17E8CF83A9162A0FC89DCA380337FCB7FDFA202801AA9D499D6AD0BBB2F6F411","type":"BUS_EVENT_TYPE_ORDER","order":{"id":"b25bc834940a966d9eea491c54c84701847d48db23ec48ecfc008ad9c96e671e","marketId":"ee4cc727547c9b278878e1fd77e4f7d4071acc7ccf43dd3c53a9f5b86875fd08","partyId":"cac331b56c0ea327a1d1a066fefc506c8af8b32a01083ae13a80533a39a42896","side":"SIDE_BUY","price":"100100000","size":"500000","remaining":"500000","timeInForce":"TIME_IN_FORCE_GTC","type":"TYPE_LIMIT","createdAt":"1694695173867137249","status":"STATUS_ACTIVE","reference":"test_ActivePeggedOrder_GTT_GTC_GFN[order_param0]-35e5435e","version":"1"},"version":1,"chainId":"testnet-001","txHash":"D8D33082236104C0E22D2354A8FA4016E9680C00A498EC2F8A2FF6FD8EAAF190"}
{"id":"1425-48","block":"76DAB044D06D7CB354794166364EF621A8E749EF986C902318E3F81AEC30E56E","type":"BUS_EVENT_TYPE_ORDER","order":{"id":"4dac0d3eb1f543344647bae27cf146974b6bebca58c10f6c2373d31c3a73c276","marketId":"ee4cc727547c9b278878e1fd77e4f7d4071acc7ccf43dd3c53a9f5b86875fd08","partyId":"1dda776c1c43896c7ca4d94dc6a7da7e86607b30ce5d205d256a062129641005","side":"SIDE_SELL","price":"120000000","size":"500000","remaining":"500000","timeInForce":"TIME_IN_FORCE_GTC","type":"TYPE_LIMIT","createdAt":"1694695174174642631","status":"STATUS_ACTIVE","reference":"test_ActivePeggedOrder_GTT_GTC_GFN[order_param0]-7d128e3e","version":"1"},"version":1,"chainId":"testnet-001","txHash":"116700EEF5EE27220FCB21A3B975995FF08EF7ECF5118F6A8C2BD7F73F482770"}
{"id":"1425-54","block":"76DAB044D06D7CB354794166364EF621A8E749EF986C902318E3F81AEC30E56E","type":"BUS_EVENT_TYPE_ORDER","order":{"id":"3e90ba157174d73df18c6d83fca0e5f719cc2aa6145d5d8436dbd31aea9716f1","marketId":"ee4cc727547c9b278878e1fd77e4f7d4071acc7ccf43dd3c53a9f5b86875fd08","partyId":"cac331b56c0ea327a1d1a066fefc506c8af8b32a01083ae13a80533a39a42896","side":"SIDE_BUY","price":"90000000","size":"500000","remaining":"500000","timeInForce":"TIME_IN_FORCE_GTC","type":"TYPE_LIMIT","createdAt":"1694695174174642631","status":"STATUS_ACTIVE","reference":"test_ActivePeggedOrder_GTT_GTC_GFN[order_param0]-3cd9fb83","version":"1"},"version":1,"chainId":"testnet-001","txHash":"B40AC08BAAD3037111FDB85CA5BF55F6AA04F6F1DB30C87D22765243FBD1457B"}
{"id":"1425-60","block":"76DAB044D06D7CB354794166364EF621A8E749EF986C902318E3F81AEC30E56E","type":"BUS_EVENT_TYPE_ORDER","order":{"id":"88af6e70c375202e92e59b08fa381e51463feeaf017987640f941c2cb469f03e","marketId":"ee4cc727547c9b278878e1fd77e4f7d4071acc7ccf43dd3c53a9f5b86875fd08","partyId":"1dda776c1c43896c7ca4d94dc6a7da7e86607b30ce5d205d256a062129641005","side":"SIDE_SELL","price":"10000000000","size":"100000","remaining":"100000","timeInForce":"TIME_IN_FORCE_GTC","type":"TYPE_LIMIT","createdAt":"1694695174174642631","status":"STATUS_ACTIVE","reference":"test_ActivePeggedOrder_GTT_GTC_GFN[order_param0]-20548c3b","version":"1"},"version":1,"chainId":"testnet-001","txHash":"04B81E66D7DE6E7F61446E4CA018535E6F5C9D3C2CF5266C48119F45FEC5695A"}
{"id":"1425-66","block":"76DAB044D06D7CB354794166364EF621A8E749EF986C902318E3F81AEC30E56E","type":"BUS_EVENT_TYPE_ORDER","order":{"id":"da005a30eedfe8362be1293c850d1e6683731721035099865ea517bfbb5df00f","marketId":"ee4cc727547c9b278878e1fd77e4f7d4071acc7ccf43dd3c53a9f5b86875fd08","partyId":"cac331b56c0ea327a1d1a066fefc506c8af8b32a01083ae13a80533a39a42896","side":"SIDE_BUY","price":"10000000","size":"100000","remaining":"100000","timeInForce":"TIME_IN_FORCE_GTC","type":"TYPE_LIMIT","createdAt":"1694695174174642631","status":"STATUS_ACTIVE","reference":"test_ActivePeggedOrder_GTT_GTC_GFN[order_param0]-7e9bfe26","version":"1"},"version":1,"chainId":"testnet-001","txHash":"ABF10802D28C443E2D94B2344782AA4327BD19CBC4F96C39EC01DFBA712413C2"}
{"id":"1428-50","block":"C16FCA30AF11A3D99478E294C607248DAFFDA606072B22B797AD3AF2B6ADF1D8","type":"BUS_EVENT_TYPE_ORDER","order":{"id":"96ed0f243570c69cd3c03503b46a68ab2af26bbcde7190b43db00e431e36677f","marketId":"ee4cc727547c9b278878e1fd77e4f7d4071acc7ccf43dd3c53a9f5b86875fd08","partyId":"1dda776c1c43896c7ca4d94dc6a7da7e86607b30ce5d205d256a062129641005","side":"SIDE_SELL","price":"95100000","size":"500000","remaining":"500000","timeInForce":"TIME_IN_FORCE_GTC","type":"TYPE_LIMIT","createdAt":"1694695175804001954","status":"STATUS_ACTIVE","reference":"test_ActivePeggedOrder_GTT_GTC_GFN[order_param0]-43a7b99a","version":"1"},"version":1,"chainId":"testnet-001","txHash":"9EF42B7E12113A5ABA45AEC441AE1187BC405431DE6BD62FAC64DF26DB0345E4"}
{"id":"1432-25","block":"816A86E0A6908D83309441BFBCF29DC961C7C786F04F2FF8558B45B5BDDFFB64","type":"BUS_EVENT_TYPE_ORDER","order":{"id":"96ed0f243570c69cd3c03503b46a68ab2af26bbcde7190b43db00e431e36677f","marketId":"ee4cc727547c9b278878e1fd77e4f7d4071acc7ccf43dd3c53a9f5b86875fd08","partyId":"1dda776c1c43896c7ca4d94dc6a7da7e86607b30ce5d205d256a062129641005","side":"SIDE_SELL","price":"95100000","size":"500000","timeInForce":"TIME_IN_FORCE_GTC","type":"TYPE_LIMIT","createdAt":"1694695175804001954","status":"STATUS_FILLED","reference":"test_ActivePeggedOrder_GTT_GTC_GFN[order_param0]-43a7b99a","updatedAt":"1694695177494380817","version":"1"},"version":1,"chainId":"testnet-001","txHash":"816A86E0A6908D83309441BFBCF29DC961C7C786F04F2FF8558B45B5BDDFFB64"}
{"id":"1432-27","block":"816A86E0A6908D83309441BFBCF29DC961C7C786F04F2FF8558B45B5BDDFFB64","type":"BUS_EVENT_TYPE_ORDER","order":{"id":"b25bc834940a966d9eea491c54c84701847d48db23ec48ecfc008ad9c96e671e","marketId":"ee4cc727547c9b278878e1fd77e4f7d4071acc7ccf43dd3c53a9f5b86875fd08","partyId":"cac331b56c0ea327a1d1a066fefc506c8af8b32a01083ae13a80533a39a42896","side":"SIDE_BUY","price":"100100000","size":"500000","timeInForce":"TIME_IN_FORCE_GTC","type":"TYPE_LIMIT","createdAt":"1694695173867137249","status":"STATUS_FILLED","reference":"test_ActivePeggedOrder_GTT_GTC_GFN[order_param0]-35e5435e","updatedAt":"1694695177494380817","version":"1"},"version":1,"chainId":"testnet-001","txHash":"816A86E0A6908D83309441BFBCF29DC961C7C786F04F2FF8558B45B5BDDFFB64"}
{"id":"1434-49","block":"1F23AF29AF9A3F799E7328E28F327831B633B49BF1CD4C32A4CE0BEE13EF797A","type":"BUS_EVENT_TYPE_ORDER","order":{"id":"75762590e6d49464b046130b358c9dcf059e3265e92886303aed14fb4f51c08b","marketId":"ee4cc727547c9b278878e1fd77e4f7d4071acc7ccf43dd3c53a9f5b86875fd08","partyId":"bff6d9cece6f20ba1523ca61dc92af16433634688ed120082386eaa59033be75","side":"SIDE_BUY","price":"80000000","size":"100000","remaining":"100000","timeInForce":"TIME_IN_FORCE_GTT","type":"TYPE_LIMIT","createdAt":"1694695178106947404","status":"STATUS_ACTIVE","expiresAt":"1694695297494380000","reference":"test_ActivePeggedOrder_GTT_GTC_GFN[order_param0]-75317d08","version":"1","batchId":"1","peggedOrder":{"reference":"PEGGED_REFERENCE_BEST_BID","offset":"10000000"}},"version":1,"chainId":"testnet-001","txHash":"40FBD3CB53D8C8C419BED3C1D1E50F96C0C563662EF4FCC93084E5B8E46C1199"}

============

{"id":"1431-44","block":"5A9D8F3646F41048935296436831583A7564E13C79C1578CDD14881BB6B1867E","type":"BUS_EVENT_TYPE_MARKET_DATA","marketData":{"markPrice":"0","bestBidPrice":"100100000","bestBidVolume":"500000","bestOfferPrice":"95100000","bestOfferVolume":"500000","bestStaticBidPrice":"100100000","bestStaticBidVolume":"500000","bestStaticOfferPrice":"95100000","bestStaticOfferVolume":"500000","midPrice":"97600000","staticMidPrice":"97600000","market":"ee4cc727547c9b278878e1fd77e4f7d4071acc7ccf43dd3c53a9f5b86875fd08","timestamp":"1694695177054415204","auctionEnd":"1694695152000000000","auctionStart":"1694695151000000000","indicativePrice":"97600000","indicativeVolume":"500000","marketTradingMode":"TRADING_MODE_OPENING_AUCTION","trigger":"AUCTION_TRIGGER_OPENING","targetStake":"1349076000000000000000","suppliedStake":"390500000000000000000000","marketValueProxy":"0","liquidityProviderFeeShare":[{"party":"066b54c711991c0078f129406bbeb1eba6913b6208ebdb0d20f15c0094318827","equityLikeShare":"1","averageEntryValuation":"390500000000000000000000","averageScore":"0","virtualStake":"390500000000000000000000.0000000000000000"}],"marketState":"STATE_PENDING","nextMarkToMarket":"-6795364578871345152","lastTradedPrice":"0","marketGrowth":"0"},"version":1,"chainId":"testnet-001","txHash":"5A9D8F3646F41048935296436831583A7564E13C79C1578CDD14881BB6B1867E"}
{"id":"1432-63","block":"816A86E0A6908D83309441BFBCF29DC961C7C786F04F2FF8558B45B5BDDFFB64","type":"BUS_EVENT_TYPE_MARKET_DATA","marketData":{"markPrice":"97600000","bestBidPrice":"90000000","bestBidVolume":"500000","bestOfferPrice":"120000000","bestOfferVolume":"500000","bestStaticBidPrice":"90000000","bestStaticBidVolume":"500000","bestStaticOfferPrice":"120000000","bestStaticOfferVolume":"500000","midPrice":"105000000","staticMidPrice":"105000000","market":"ee4cc727547c9b278878e1fd77e4f7d4071acc7ccf43dd3c53a9f5b86875fd08","timestamp":"1694695177494380817","openInterest":"500000","indicativePrice":"0","marketTradingMode":"TRADING_MODE_CONTINUOUS","targetStake":"1349076000000000000000","suppliedStake":"390500000000000000000000","marketValueProxy":"0","liquidityProviderFeeShare":[{"party":"066b54c711991c0078f129406bbeb1eba6913b6208ebdb0d20f15c0094318827","equityLikeShare":"1","averageEntryValuation":"390500000000000000000000","averageScore":"1","virtualStake":"390500000000000000000000.0000000000000000"}],"marketState":"STATE_ACTIVE","nextMarkToMarket":"1694695177494380817","lastTradedPrice":"97600000","marketGrowth":"0"},"version":1,"chainId":"testnet-001","txHash":"816A86E0A6908D83309441BFBCF29DC961C7C786F04F2FF8558B45B5BDDFFB64"}
EVODelavega commented 1 year ago

After discussing with @jgsbennett and going through everything in detail, we've confirmed that the orders are submitted, and the market data shows an indicative price, supplied stake > target stake (ie the market is ready to leave opening auction), but opening auction doesn't end for another 4 blocks. This delay seems to be consistent across runs, too.

EVODelavega commented 1 year ago

The issue below is explained as the 4 blocks of delay between the orders getting placed and the opening auction ending are due to the price monitoring bounds statevar getting initialised, and waiting for a match. Examining the statevar events shows the event is sent immediately after the data is available, and the match event is emitted 2 blocks later, once the bounds are initialised, the next tick the market leaves opening auction. A block-by-block overview of what's happening, and why opening auction ends later than expected:

Which lines up perfectly with what is found in the event logs when running the tests (e.g. orders submitted on block 458 -> market leaves auction on block 462)