diff --git a/.avalanche-cli.json b/.avalanche-cli.json index 4564c6702d..163cb14496 100644 --- a/.avalanche-cli.json +++ b/.avalanche-cli.json @@ -1,5 +1,6 @@ { "node-config": { "log-level": "info" - } -} + }, + "SingleNodeEnabled": false +} \ No newline at end of file diff --git a/core/types/transaction.go b/core/types/transaction.go index 34c185a7b7..0a85d34e99 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -639,6 +639,22 @@ func (t *TransactionsByPriceAndNonce) Pop() { heap.Pop(&t.heads) } +func (t *TransactionsByPriceAndNonce) Copy() *TransactionsByPriceAndNonce { + txs := make(map[common.Address]Transactions, len(t.txs)) + for acc, accTxs := range t.txs { + txs[acc] = make(Transactions, len(accTxs)) + copy(txs[acc], accTxs) + } + heads := make(TxByPriceAndTime, len(t.heads)) + copy(heads, t.heads) + return &TransactionsByPriceAndNonce{ + txs: txs, + heads: heads, + signer: t.signer, + baseFee: big.NewInt(0).Set(t.baseFee), + } +} + // copyAddressPtr copies an address. func copyAddressPtr(a *common.Address) *common.Address { if a == nil { diff --git a/eth/backend.go b/eth/backend.go index a8de24fad9..71bfae0ab4 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -335,6 +335,11 @@ func (s *Ethereum) SetEtherbase(etherbase common.Address) { s.miner.SetEtherbase(etherbase) } +func (s *Ethereum) SetOrderbookChecker(orderBookChecker miner.OrderbookChecker) { + s.miner.SetOrderbookChecker(orderBookChecker) + +} + func (s *Ethereum) Miner() *miner.Miner { return s.miner } func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager } diff --git a/miner/miner.go b/miner/miner.go index 14e5ba8d75..f22b81b475 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -64,6 +64,10 @@ func (miner *Miner) SetEtherbase(addr common.Address) { miner.worker.setEtherbase(addr) } +func (miner *Miner) SetOrderbookChecker(orderBookChecker OrderbookChecker) { + miner.worker.setOrderbookChecker(orderBookChecker) +} + func (miner *Miner) GenerateBlock(predicateContext *precompileconfig.PredicateContext) (*types.Block, error) { return miner.worker.commitNewWork(predicateContext) } diff --git a/miner/orderbook_checker.go b/miner/orderbook_checker.go new file mode 100644 index 0000000000..a2cf56fb12 --- /dev/null +++ b/miner/orderbook_checker.go @@ -0,0 +1,14 @@ +package miner + +import ( + "math/big" + + "github.com/ava-labs/subnet-evm/core/state" + "github.com/ava-labs/subnet-evm/core/types" + "github.com/ethereum/go-ethereum/common" +) + +type OrderbookChecker interface { + GetMatchingTxs(tx *types.Transaction, stateDB *state.StateDB, blockNumber *big.Int) map[common.Address]types.Transactions + ResetMemoryDB() +} diff --git a/miner/worker.go b/miner/worker.go index bac57322fc..ef008af38b 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -99,6 +99,8 @@ type worker struct { mu sync.RWMutex // The lock used to protect the coinbase and extra fields coinbase common.Address clock *mockable.Clock // Allows us mock the clock for testing + + orderbookChecker OrderbookChecker } func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, clock *mockable.Clock) *worker { @@ -123,6 +125,10 @@ func (w *worker) setEtherbase(addr common.Address) { w.coinbase = addr } +func (w *worker) setOrderbookChecker(orderBookChecker OrderbookChecker) { + w.orderbookChecker = orderBookChecker +} + // commitNewWork generates several new sealing tasks based on the parent block. func (w *worker) commitNewWork(predicateContext *precompileconfig.PredicateContext) (*types.Block, error) { w.mu.RLock() @@ -229,16 +235,38 @@ func (w *worker) commitNewWork(predicateContext *precompileconfig.PredicateConte } if len(localTxs) > 0 { txs := types.NewTransactionsByPriceAndNonce(env.signer, localTxs, header.BaseFee) + txsCopy := txs.Copy() w.commitTransactions(env, txs, header.Coinbase) + w.commitOrderbookTxs(env, txsCopy, header) } if len(remoteTxs) > 0 { txs := types.NewTransactionsByPriceAndNonce(env.signer, remoteTxs, header.BaseFee) + txsCopy := txs.Copy() w.commitTransactions(env, txs, header.Coinbase) + w.commitOrderbookTxs(env, txsCopy, header) } + w.orderbookChecker.ResetMemoryDB() + return w.commit(env) } +func (w *worker) commitOrderbookTxs(env *environment, transactions *types.TransactionsByPriceAndNonce, header *types.Header) { + for { + tx := transactions.Peek() + if tx == nil { + break + } + transactions.Pop() + + orderbookTxs := w.orderbookChecker.GetMatchingTxs(tx, env.state, header.Number) + if orderbookTxs != nil { + txsByPrice := types.NewTransactionsByPriceAndNonce(env.signer, orderbookTxs, header.BaseFee) + w.commitTransactions(env, txsByPrice, header.Coinbase) + } + } +} + func (w *worker) createCurrentEnvironment(predicateContext *precompileconfig.PredicateContext, parent *types.Header, header *types.Header, tstart time.Time) (*environment, error) { state, err := w.chain.StateAt(parent.Root) if err != nil { diff --git a/plugin/evm/limit_order.go b/plugin/evm/limit_order.go index 3ca4661755..eb5e20c107 100644 --- a/plugin/evm/limit_order.go +++ b/plugin/evm/limit_order.go @@ -38,6 +38,8 @@ type LimitOrderProcesser interface { GetTestingAPI() *orderbook.TestingAPI GetTradingAPI() *orderbook.TradingAPI RunMatchingPipeline() + GetMemoryDB() orderbook.LimitOrderDatabase + GetLimitOrderTxProcessor() orderbook.LimitOrderTxProcessor } type limitOrderProcesser struct { @@ -206,6 +208,14 @@ func (lop *limitOrderProcesser) GetTestingAPI() *orderbook.TestingAPI { return orderbook.NewTestingAPI(lop.memoryDb, lop.backend, lop.configService, lop.hubbleDB) } +func (lop *limitOrderProcesser) GetMemoryDB() orderbook.LimitOrderDatabase { + return lop.memoryDb +} + +func (lop *limitOrderProcesser) GetLimitOrderTxProcessor() orderbook.LimitOrderTxProcessor { + return lop.limitOrderTxProcessor +} + func (lop *limitOrderProcesser) listenAndStoreLimitOrderTransactions() { logsCh := make(chan []*types.Log) logsSubscription := lop.backend.SubscribeHubbleLogsEvent(logsCh) diff --git a/plugin/evm/orderbook/config_service.go b/plugin/evm/orderbook/config_service.go index 9411e2fae5..36de29d50f 100644 --- a/plugin/evm/orderbook/config_service.go +++ b/plugin/evm/orderbook/config_service.go @@ -39,6 +39,7 @@ type IConfigService interface { type ConfigService struct { blockChain *core.BlockChain + stateDB *state.StateDB } func NewConfigService(blockChain *core.BlockChain) IConfigService { @@ -47,6 +48,20 @@ func NewConfigService(blockChain *core.BlockChain) IConfigService { } } +func NewConfigServiceFromStateDB(stateDB *state.StateDB) IConfigService { + return &ConfigService{ + stateDB: stateDB, + } +} + +func (cs *ConfigService) getStateAtCurrentBlock() *state.StateDB { + if cs.stateDB != nil { + return cs.stateDB + } + stateDB, _ := cs.blockChain.StateAt(cs.blockChain.CurrentBlock().Root) + return stateDB +} + func (cs *ConfigService) GetAcceptableBounds(market Market) (*big.Int, *big.Int) { return bibliophile.GetAcceptableBounds(cs.getStateAtCurrentBlock(), int64(market)) } @@ -79,11 +94,6 @@ func (cs *ConfigService) GetPriceMultiplier(market Market) *big.Int { return bibliophile.GetMultiplier(cs.getStateAtCurrentBlock(), int64(market)) } -func (cs *ConfigService) getStateAtCurrentBlock() *state.StateDB { - stateDB, _ := cs.blockChain.StateAt(cs.blockChain.CurrentBlock().Root) - return stateDB -} - func (cs *ConfigService) GetActiveMarketsCount() int64 { return bibliophile.GetActiveMarketsCount(cs.getStateAtCurrentBlock()) } diff --git a/plugin/evm/orderbook/matching_pipeline.go b/plugin/evm/orderbook/matching_pipeline.go index 97f01cc6b6..8a821ccb5c 100644 --- a/plugin/evm/orderbook/matching_pipeline.go +++ b/plugin/evm/orderbook/matching_pipeline.go @@ -7,6 +7,7 @@ import ( "sync" "time" + "github.com/ava-labs/subnet-evm/core/types" hu "github.com/ava-labs/subnet-evm/plugin/evm/orderbook/hubbleutils" "github.com/ava-labs/subnet-evm/utils" "github.com/ethereum/go-ethereum/common" @@ -42,6 +43,18 @@ func NewMatchingPipeline( } } +func NewTemporaryMatchingPipeline( + db LimitOrderDatabase, + lotp LimitOrderTxProcessor, + configService IConfigService) *MatchingPipeline { + + return &MatchingPipeline{ + db: db, + lotp: lotp, + configService: configService, + } +} + func (pipeline *MatchingPipeline) RunSanitization() { pipeline.db.RemoveExpiredSignedOrders() } @@ -106,6 +119,47 @@ func (pipeline *MatchingPipeline) Run(blockNumber *big.Int) bool { return false } +func (pipeline *MatchingPipeline) GetOrderMatchingTransactions(blockNumber *big.Int, markets []Market) map[common.Address]types.Transactions { + pipeline.mu.Lock() + defer pipeline.mu.Unlock() + + activeMarkets := pipeline.GetActiveMarkets() + log.Info("MatchingPipeline:GetOrderMatchingTransactions") + + if len(activeMarkets) == 0 { + return nil + } + + // start fresh and purge all local transactions + pipeline.lotp.PurgeOrderBookTxs() + + // fetch various hubble market params and run the matching engine + hState := hu.GetHubbleState() + hState.OraclePrices = hu.ArrayToMap(pipeline.configService.GetUnderlyingPrices()) + + marginMap := make(map[common.Address]*big.Int) + for addr, trader := range pipeline.db.GetAllTraders() { + userState := &hu.UserState{ + Positions: translatePositions(trader.Positions), + Margins: getMargins(&trader, len(hState.Assets)), + PendingFunding: getTotalFunding(&trader, hState.ActiveMarkets), + ReservedMargin: new(big.Int).Set(trader.Margin.Reserved), + // this is the only leveldb read, others above are in-memory reads + ReduceOnlyAmounts: pipeline.configService.GetReduceOnlyAmounts(addr), + } + marginMap[addr] = hu.GetAvailableMargin(hState, userState) + } + for _, market := range markets { + orders := pipeline.fetchOrders(market, hState.OraclePrices[market], map[common.Hash]struct{}{}, blockNumber) + upperBound, _ := pipeline.configService.GetAcceptableBounds(market) + pipeline.runMatchingEngine(pipeline.lotp, orders.longOrders, orders.shortOrders, marginMap, hState.MinAllowableMargin, hState.TakerFee, upperBound) + } + + orderbookTxs := pipeline.lotp.GetOrderBookTxs() + pipeline.lotp.PurgeOrderBookTxs() + return orderbookTxs +} + type Orders struct { longOrders []Order shortOrders []Order diff --git a/plugin/evm/orderbook/mocks.go b/plugin/evm/orderbook/mocks.go index 9ff2bdd61b..7a89f5155e 100644 --- a/plugin/evm/orderbook/mocks.go +++ b/plugin/evm/orderbook/mocks.go @@ -200,6 +200,10 @@ func (lotp *MockLimitOrderTxProcessor) GetOrderBookTxsCount() uint64 { return uint64(args.Int(0)) } +func (lotp *MockLimitOrderTxProcessor) GetOrderBookTxs() map[common.Address]types.Transactions { + return nil +} + func (lotp *MockLimitOrderTxProcessor) ExecuteFundingPaymentTx() error { return nil } diff --git a/plugin/evm/orderbook/temp_matching.go b/plugin/evm/orderbook/temp_matching.go new file mode 100644 index 0000000000..10bbcca33c --- /dev/null +++ b/plugin/evm/orderbook/temp_matching.go @@ -0,0 +1,281 @@ +package orderbook + +import ( + "encoding/json" + "math/big" + + "github.com/ava-labs/subnet-evm/accounts/abi" + "github.com/ava-labs/subnet-evm/core/state" + "github.com/ava-labs/subnet-evm/core/types" + "github.com/ava-labs/subnet-evm/metrics" + "github.com/ava-labs/subnet-evm/plugin/evm/orderbook/abis" + "github.com/ava-labs/subnet-evm/precompile/contracts/bibliophile" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/log" +) + +var ( + getMatchingTxsErrorCounter = metrics.NewRegisteredCounter("GetMatchingTxs_errors", nil) + getMatchingTxsWarningCounter = metrics.NewRegisteredCounter("GetMatchingTxs_warnings", nil) +) + +type TempMatcher struct { + db LimitOrderDatabase + tempDB LimitOrderDatabase + lotp LimitOrderTxProcessor + orderBookABI abi.ABI + limitOrderBookABI abi.ABI + iocOrderBookABI abi.ABI +} + +func NewTempMatcher(db LimitOrderDatabase, lotp LimitOrderTxProcessor) *TempMatcher { + orderBookABI, err := abi.FromSolidityJson(string(abis.OrderBookAbi)) + if err != nil { + panic(err) + } + + limitOrderBookABI, err := abi.FromSolidityJson(string(abis.LimitOrderBookAbi)) + if err != nil { + panic(err) + } + + iocOrderBookABI, err := abi.FromSolidityJson(string(abis.IOCOrderBookAbi)) + if err != nil { + panic(err) + } + + return &TempMatcher{ + db: db, + lotp: lotp, + orderBookABI: orderBookABI, + limitOrderBookABI: limitOrderBookABI, + iocOrderBookABI: iocOrderBookABI, + } +} + +func (matcher *TempMatcher) GetMatchingTxs(tx *types.Transaction, stateDB *state.StateDB, blockNumber *big.Int) map[common.Address]types.Transactions { + var isError bool + defer func() { + if isError { + getMatchingTxsErrorCounter.Inc(1) + } + }() + + to := tx.To() + + if to == nil || len(tx.Data()) < 4 { + return nil + } + + method := tx.Data()[:4] + methodData := tx.Data()[4:] + + var err error + var markets []Market + if matcher.tempDB == nil { + matcher.tempDB, err = matcher.db.GetOrderBookDataCopy() + if err != nil { + log.Error("GetMatchingTxs: error in fetching tempDB", "err", err) + isError = true + return nil + } + } + switch *to { + case LimitOrderBookContractAddress: + abiMethod, err := matcher.limitOrderBookABI.MethodById(method) + if err != nil { + log.Error("GetMatchingTxs: error in fetching abiMethod", "err", err) + isError = true + return nil + } + + // check for placeOrders and cancelOrders txs + switch abiMethod.Name { + case "placeOrders": + orders, err := getLimitOrdersFromMethodData(abiMethod, methodData, blockNumber) + if err != nil { + log.Error("GetMatchingTxs: error in fetching orders from placeOrders tx data", "err", err) + isError = true + return nil + } + marketsMap := make(map[Market]struct{}) + for _, order := range orders { + // the transaction in the args is supposed to be already committed in the db, so the status should be placed + status := bibliophile.GetOrderStatus(stateDB, order.Id) + if status != 1 { // placed + log.Warn("GetMatchingTxs: invalid limit order status", "status", status, "order", order.Id.String()) + getMatchingTxsWarningCounter.Inc(1) + continue + } + + matcher.tempDB.Add(order) + marketsMap[order.Market] = struct{}{} + } + + markets = make([]Market, 0, len(marketsMap)) + for market := range marketsMap { + markets = append(markets, market) + } + + case "cancelOrders": + orders, err := getLimitOrdersFromMethodData(abiMethod, methodData, blockNumber) + if err != nil { + log.Error("GetMatchingTxs: error in fetching orders from cancelOrders tx data", "err", err) + isError = true + return nil + } + for _, order := range orders { + if err := matcher.tempDB.SetOrderStatus(order.Id, Cancelled, "", blockNumber.Uint64()); err != nil { + log.Error("GetMatchingTxs: error in SetOrderStatus", "orderId", order.Id.String(), "err", err) + return nil + } + } + // no need to run matching + return nil + default: + return nil + } + + case IOCOrderBookContractAddress: + abiMethod, err := matcher.iocOrderBookABI.MethodById(method) + if err != nil { + log.Error("Error in fetching abiMethod", "err", err) + isError = true + return nil + } + + switch abiMethod.Name { + case "placeOrders": + orders, err := getIOCOrdersFromMethodData(abiMethod, methodData, blockNumber) + if err != nil { + log.Error("Error in fetching orders", "err", err) + isError = true + return nil + } + marketsMap := make(map[Market]struct{}) + for _, order := range orders { + // the transaction in the args is supposed to be already committed in the db, so the status should be placed + status := bibliophile.IOCGetOrderStatus(stateDB, order.Id) + if status != 1 { // placed + log.Warn("GetMatchingTxs: invalid ioc order status", "status", status, "order", order.Id.String()) + getMatchingTxsWarningCounter.Inc(1) + continue + } + + matcher.tempDB.Add(order) + marketsMap[order.Market] = struct{}{} + } + + markets = make([]Market, 0, len(marketsMap)) + for market := range marketsMap { + markets = append(markets, market) + } + default: + return nil + } + default: + // tx is not related to orderbook + return nil + } + + configService := NewConfigServiceFromStateDB(stateDB) + tempMatchingPipeline := NewTemporaryMatchingPipeline(matcher.tempDB, matcher.lotp, configService) + + return tempMatchingPipeline.GetOrderMatchingTransactions(blockNumber, markets) +} + +func (matcher *TempMatcher) ResetMemoryDB() { + matcher.tempDB = nil +} + +func getLimitOrdersFromMethodData(abiMethod *abi.Method, methodData []byte, blockNumber *big.Int) ([]*Order, error) { + unpackedData, err := abiMethod.Inputs.Unpack(methodData) + if err != nil { + log.Error("Error in unpacking data", "err", err) + return nil, err + } + + limitOrders := []*LimitOrder{} + ordersInterface := unpackedData[0] + + marshalledOrders, _ := json.Marshal(ordersInterface) + err = json.Unmarshal(marshalledOrders, &limitOrders) + if err != nil { + log.Error("Error in unmarshalling orders", "err", err) + return nil, err + } + + orders := []*Order{} + for _, limitOrder := range limitOrders { + orderId, err := limitOrder.Hash() + if err != nil { + log.Error("Error in hashing order", "err", err) + // @todo: send to metrics + return nil, err + } + + order := &Order{ + Id: orderId, + Market: Market(limitOrder.AmmIndex.Int64()), + PositionType: getPositionTypeBasedOnBaseAssetQuantity(limitOrder.BaseAssetQuantity), + Trader: limitOrder.Trader, + BaseAssetQuantity: limitOrder.BaseAssetQuantity, + FilledBaseAssetQuantity: big.NewInt(0), + Price: limitOrder.Price, + RawOrder: limitOrder, + Salt: limitOrder.Salt, + ReduceOnly: limitOrder.ReduceOnly, + BlockNumber: blockNumber, + OrderType: Limit, + } + orders = append(orders, order) + } + + return orders, nil +} + +func getIOCOrdersFromMethodData(abiMethod *abi.Method, methodData []byte, blockNumber *big.Int) ([]*Order, error) { + unpackedData, err := abiMethod.Inputs.Unpack(methodData) + if err != nil { + log.Error("Error in unpacking data", "err", err) + return nil, err + } + + iocOrders := []*IOCOrder{} + ordersInterface := unpackedData[0] + + marshalledOrders, _ := json.Marshal(ordersInterface) + err = json.Unmarshal(marshalledOrders, &iocOrders) + if err != nil { + log.Error("Error in unmarshalling orders", "err", err) + return nil, err + } + + orders := []*Order{} + for _, iocOrder := range iocOrders { + orderId, err := iocOrder.Hash() + if err != nil { + log.Error("Error in hashing order", "err", err) + // @todo: send to metrics + return nil, err + } + + order := &Order{ + Id: orderId, + Market: Market(iocOrder.AmmIndex.Int64()), + PositionType: getPositionTypeBasedOnBaseAssetQuantity(iocOrder.BaseAssetQuantity), + Trader: iocOrder.Trader, + BaseAssetQuantity: iocOrder.BaseAssetQuantity, + FilledBaseAssetQuantity: big.NewInt(0), + Price: iocOrder.Price, + RawOrder: iocOrder, + Salt: iocOrder.Salt, + ReduceOnly: iocOrder.ReduceOnly, + BlockNumber: blockNumber, + OrderType: Limit, + } + orders = append(orders, order) + } + + return orders, nil +} diff --git a/plugin/evm/orderbook/tx_processor.go b/plugin/evm/orderbook/tx_processor.go index 2be9ec15d0..6697319b5a 100644 --- a/plugin/evm/orderbook/tx_processor.go +++ b/plugin/evm/orderbook/tx_processor.go @@ -32,6 +32,7 @@ var IOCOrderBookContractAddress = common.HexToAddress("0x03000000000000000000000 type LimitOrderTxProcessor interface { GetOrderBookTxsCount() uint64 + GetOrderBookTxs() map[common.Address]types.Transactions SetOrderBookTxsBlockNumber(blockNumber uint64) PurgeOrderBookTxs() ExecuteMatchedOrdersTx(incomingOrder Order, matchedOrder Order, fillAmount *big.Int) error @@ -244,6 +245,10 @@ func (lotp *limitOrderTxProcessor) GetOrderBookTxsCount() uint64 { return lotp.txPool.GetOrderBookTxsCount() } +func (lotp *limitOrderTxProcessor) GetOrderBookTxs() map[common.Address]types.Transactions { + return lotp.txPool.GetOrderBookTxs() +} + func (lotp *limitOrderTxProcessor) SetOrderBookTxsBlockNumber(blockNumber uint64) { lotp.txPool.SetOrderBookTxsBlockNumber(blockNumber) } diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 30298ca05f..b17d94be3e 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -569,6 +569,8 @@ func (vm *VM) initializeChain(lastAcceptedHash common.Hash, ethConfig ethconfig. vm.miner = vm.eth.Miner() vm.limitOrderProcesser = vm.NewLimitOrderProcesser() + tempMatcher := orderbook.NewTempMatcher(vm.limitOrderProcesser.GetMemoryDB(), vm.limitOrderProcesser.GetLimitOrderTxProcessor()) + vm.eth.SetOrderbookChecker(tempMatcher) vm.eth.Start() return vm.initChainState(vm.blockChain.LastAcceptedBlock()) } diff --git a/precompile/contracts/bibliophile/api.go b/precompile/contracts/bibliophile/api.go index 0d1114aea7..313a7b18da 100644 --- a/precompile/contracts/bibliophile/api.go +++ b/precompile/contracts/bibliophile/api.go @@ -182,7 +182,7 @@ type OrderDetails struct { func GetIOCOrdersVariables(stateDB contract.StateDB, orderHash common.Hash) VariablesReadFromIOCOrdersSlots { blockPlaced := iocGetBlockPlaced(stateDB, orderHash) filledAmount := iocGetOrderFilledAmount(stateDB, orderHash) - orderStatus := iocGetOrderStatus(stateDB, orderHash) + orderStatus := IOCGetOrderStatus(stateDB, orderHash) iocExpirationCap := iocGetExpirationCap(stateDB) return VariablesReadFromIOCOrdersSlots{ @@ -203,7 +203,7 @@ type VariablesReadFromOrderbookSlots struct { func GetOrderBookVariables(stateDB contract.StateDB, traderAddress string, senderAddress string, orderHash common.Hash) VariablesReadFromOrderbookSlots { blockPlaced := getBlockPlaced(stateDB, orderHash) filledAmount := getOrderFilledAmount(stateDB, orderHash) - orderStatus := getOrderStatus(stateDB, orderHash) + orderStatus := GetOrderStatus(stateDB, orderHash) isTradingAuthoriy := IsTradingAuthority(stateDB, common.HexToAddress(traderAddress), common.HexToAddress(senderAddress)) return VariablesReadFromOrderbookSlots{ OrderDetails: OrderDetails{ diff --git a/precompile/contracts/bibliophile/client.go b/precompile/contracts/bibliophile/client.go index c03a219964..688c815e00 100644 --- a/precompile/contracts/bibliophile/client.go +++ b/precompile/contracts/bibliophile/client.go @@ -120,7 +120,7 @@ func (b *bibliophileClient) GetOrderFilledAmount(orderHash [32]byte) *big.Int { } func (b *bibliophileClient) GetOrderStatus(orderHash [32]byte) int64 { - return getOrderStatus(b.accessibleState.GetStateDB(), orderHash) + return GetOrderStatus(b.accessibleState.GetStateDB(), orderHash) } func (b *bibliophileClient) IOC_GetBlockPlaced(orderHash [32]byte) *big.Int { @@ -132,7 +132,7 @@ func (b *bibliophileClient) IOC_GetOrderFilledAmount(orderHash [32]byte) *big.In } func (b *bibliophileClient) IOC_GetOrderStatus(orderHash [32]byte) int64 { - return iocGetOrderStatus(b.accessibleState.GetStateDB(), orderHash) + return IOCGetOrderStatus(b.accessibleState.GetStateDB(), orderHash) } func (b *bibliophileClient) IsTradingAuthority(trader, senderOrSigner common.Address) bool { diff --git a/precompile/contracts/bibliophile/ioc_order_book.go b/precompile/contracts/bibliophile/ioc_order_book.go index d665dc106b..4199fc7dd9 100644 --- a/precompile/contracts/bibliophile/ioc_order_book.go +++ b/precompile/contracts/bibliophile/ioc_order_book.go @@ -27,7 +27,7 @@ func iocGetOrderFilledAmount(stateDB contract.StateDB, orderHash [32]byte) *big. return fromTwosComplement(num) } -func iocGetOrderStatus(stateDB contract.StateDB, orderHash [32]byte) int64 { +func IOCGetOrderStatus(stateDB contract.StateDB, orderHash [32]byte) int64 { orderInfo := iocOrderInfoMappingStorageSlot(orderHash) return new(big.Int).SetBytes(stateDB.GetState(common.HexToAddress(IOC_ORDERBOOK_ADDRESS), common.BigToHash(new(big.Int).Add(orderInfo, big.NewInt(2)))).Bytes()).Int64() } diff --git a/precompile/contracts/bibliophile/limit_order_book.go b/precompile/contracts/bibliophile/limit_order_book.go index 52984b6bf5..7e67653cfc 100644 --- a/precompile/contracts/bibliophile/limit_order_book.go +++ b/precompile/contracts/bibliophile/limit_order_book.go @@ -22,7 +22,7 @@ func getOrderFilledAmount(stateDB contract.StateDB, orderHash [32]byte) *big.Int return fromTwosComplement(num) } -func getOrderStatus(stateDB contract.StateDB, orderHash [32]byte) int64 { +func GetOrderStatus(stateDB contract.StateDB, orderHash [32]byte) int64 { orderInfo := orderInfoMappingStorageSlot(orderHash) return new(big.Int).SetBytes(stateDB.GetState(common.HexToAddress(LIMIT_ORDERBOOK_GENESIS_ADDRESS), common.BigToHash(new(big.Int).Add(orderInfo, big.NewInt(3)))).Bytes()).Int64() } diff --git a/scripts/run_local.sh b/scripts/run_local.sh index f99f4515dc..9d9e033511 100755 --- a/scripts/run_local.sh +++ b/scripts/run_local.sh @@ -19,7 +19,7 @@ then echo "31b571bf6894a248831ff937bb49f7754509fe93bbd2517c9c73c4144c0e97dc" > $FILE fi -avalanche subnet create localnet --force --custom --genesis genesis.json --vm custom_evm.bin --config .avalanche-cli.json +avalanche subnet create localnet --force --custom --genesis genesis.json --vm custom_evm.bin --config .avalanche-cli.json --teleporter=false # configure and add chain.json avalanche subnet configure localnet --chain-config chain.json --config .avalanche-cli.json