Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Big database upgrade #793

Merged
merged 73 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
784ca98
Strip out all existing database code
albrow Apr 21, 2020
5aadef0
rename meshdb package to db
albrow Apr 21, 2020
3fba1fd
Implement first db tests for adding/finding orders
albrow Apr 23, 2020
87c6cdb
Add basic support for Orders and MiniHeaders
albrow Apr 24, 2020
549d690
Implement and test UpdateOrder
albrow Apr 24, 2020
6a17d86
Implement sorting orders
albrow Apr 25, 2020
192739b
Imlpement and test limit and offset
albrow Apr 27, 2020
ac01463
Implement and test filters for finding orders
albrow Apr 28, 2020
decacf6
Add fields for parsed MakerAssetData and MakerFeeAssetData
albrow Apr 28, 2020
868fab3
Add test cases for filtering based on parsed maker asset data
albrow Apr 28, 2020
bf3eacb
Implement and test helper methods for filtering based on parsed asset…
albrow Apr 28, 2020
bf210b9
Rename some FilterOpts fields
albrow Apr 28, 2020
d6eff8c
Remove unneeded quotes
albrow Apr 29, 2020
0b49097
Add OF prefix to OrderField constants
albrow Apr 29, 2020
f9ee7cb
Implement and test MiniHeaders query options
albrow Apr 29, 2020
aa4ef5a
Implement and test deleting orders with a filter
albrow May 7, 2020
a6352f7
Implement and test DeleteOrder
albrow May 7, 2020
6be01f3
Refactor db package to use common/types
albrow May 8, 2020
48f3131
Implement and test deleting miniHeaders. Adjust implementation of Del…
albrow May 11, 2020
b4ea6cc
Update all types. Fix build
albrow May 12, 2020
68fb694
Automatically remove miniHeaders above retention limit
albrow May 13, 2020
89969a7
Add new options for database to configure max mini headers
albrow May 13, 2020
29fe92b
Get all blockwatch tests passing :smile:
albrow May 13, 2020
566fc88
Add new db options
albrow May 13, 2020
8235d99
Implement and test CountOrders
albrow May 14, 2020
6e4c613
Begin fixing some bugs in order watcher tests
albrow May 15, 2020
6e9e00c
Uncomment all remaining orderwatcher tests (except max expiration)
albrow May 15, 2020
199b39c
Implement and test metadata methods
albrow May 16, 2020
c410179
Fix bug in sqltypes.BigInt. Get ratelimit tests passing
albrow May 19, 2020
7890689
Fix some additional tests and unimplemented methods in core
albrow May 19, 2020
1a84800
Implement core.GetStats. Move data dir for most integration tests to …
albrow May 19, 2020
ec12836
Implement new getOrders RPC endpoint
albrow May 19, 2020
9efd2ec
Re-enable ordersync tests
albrow May 19, 2020
b597e54
Remove expirationwatch package
albrow May 20, 2020
1dbc4a8
Return db.ErrNotFound where appropriate. Remove old TODOs
albrow May 20, 2020
3c9251c
Set up basic skeleton for Dexie.js implementation
albrow May 22, 2020
cfb91dd
Implement most order methods in Dexie.js
albrow May 27, 2020
b68c720
Fix bugs and add support for order queries with one filter
albrow May 27, 2020
3f7ed83
Add support for multiple filters
albrow May 27, 2020
8a95bc5
Use checkOrderQuery function for both Dexie and SQL
albrow May 28, 2020
d1ec765
Fix bug in SQL implementation involving big numbers
albrow May 28, 2020
477c081
Add support for multiple sort values in Dexie
albrow May 28, 2020
7e1b7a3
Implement AddMiniHeaders in Dexie
albrow May 29, 2020
0e00436
Implement remaining MiniHeaders methods in Dexie
albrow May 29, 2020
3e1fbbf
Implement Metadata methods in Dexie
albrow May 29, 2020
519c471
Fix failing TypeScript and Wasm tests
albrow May 29, 2020
8e47c83
Fix some build issues
albrow May 29, 2020
6a7f447
Fix bug in OrderWatcher
albrow Jun 1, 2020
aafb749
Fix failing conversion tests
albrow Jun 1, 2020
55bbd17
Fix any remaining failing tests
albrow Jun 2, 2020
02f134f
Fix linter errors
albrow Jun 2, 2020
1123b24
Fix build errors
albrow Jun 2, 2020
87f80f1
Update yarn.lock
albrow Jun 2, 2020
59763d7
Add backwards compatibility layer for FilteredPaginationSubprotocol
albrow Jun 3, 2020
036d0e0
Re-use existing asset data decoder from orderwatcher
albrow Jun 3, 2020
55b9fe4
Remove remaining uses of goleveldb
albrow Jun 3, 2020
f577dc4
Improve handling of db closed error
albrow Jun 3, 2020
b270e87
Rename some identifiers
albrow Jun 3, 2020
adee74f
Address some low hanging TODOs
albrow Jun 3, 2020
c1d647a
De-dupe and refactor DB test cases
albrow Jun 4, 2020
be45272
Change how context is passed in to core.App
albrow Jun 4, 2020
85552a1
Add missing exit 0 to some clean commands
albrow Jun 4, 2020
d9f1130
Address remaining TODOs in sql_implementation
albrow Jun 4, 2020
0417824
Address remaining TODOs in database.ts
albrow Jun 4, 2020
73e5ee2
Address remaining TODOs in order_watcher.go
albrow Jun 4, 2020
6e750f2
Minor changes and cleanup
albrow Jun 4, 2020
8b48266
Fix yarn.lock
albrow Jun 8, 2020
d17b79b
Respond to PR feedback
albrow Jun 9, 2020
b9e1e9d
Fix bug in database.ts
albrow Jun 9, 2020
4f508b9
Address remaining PR feedback
albrow Jun 9, 2020
df6ac87
Address third round PR feedback
albrow Jun 9, 2020
c750012
Address review feedback part 4
albrow Jun 9, 2020
016ee05
Fix linter
albrow Jun 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions cmd/db-integrity-check/main.go

This file was deleted.

10 changes: 5 additions & 5 deletions cmd/mesh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ func main() {
log.WithField("error", err.Error()).Fatal("could not parse environment variables")
}

// Start core.App.
app, err := core.New(coreConfig)
// Initialize core.App.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
app, err := core.New(ctx, coreConfig)
if err != nil {
log.WithField("error", err.Error()).Fatal("could not initialize app")
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Below, we will start several independent goroutines. We use separate
// channels to communicate errors and a waitgroup to wait for all goroutines
Expand All @@ -55,7 +55,7 @@ func main() {
wg.Add(1)
go func() {
defer wg.Done()
if err := app.Start(ctx); err != nil {
if err := app.Start(); err != nil {
coreErrChan <- err
}
}()
Expand Down
11 changes: 6 additions & 5 deletions cmd/mesh/rpc_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/0xProject/0x-mesh/rpc"
"github.com/0xProject/0x-mesh/zeroex"
"github.com/0xProject/0x-mesh/zeroex/ordervalidator"
"github.com/ethereum/go-ethereum/common"
ethrpc "github.com/ethereum/go-ethereum/rpc"
peerstore "github.com/libp2p/go-libp2p-peerstore"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -60,11 +61,10 @@ func instantiateServer(ctx context.Context, app *core.App, rpcAddr string) *rpc.
}

// GetOrders is called when an RPC client calls GetOrders.
func (handler *rpcHandler) GetOrders(page, perPage int, snapshotID string) (result *types.GetOrdersResponse, err error) {
func (handler *rpcHandler) GetOrders(perPage int, minOrderHashHex string) (result *types.GetOrdersResponse, err error) {
log.WithFields(map[string]interface{}{
"page": page,
"perPage": perPage,
"snapshotID": snapshotID,
"perPage": perPage,
"minOrderHashHex": minOrderHashHex,
}).Debug("received GetOrders request via RPC")
// Catch panics, log stack trace and return RPC error message
defer func() {
Expand All @@ -82,7 +82,8 @@ func (handler *rpcHandler) GetOrders(page, perPage int, snapshotID string) (resu
err = errors.New("method handler crashed in GetOrders RPC call (check logs for stack trace)")
}
}()
getOrdersResponse, err := handler.app.GetOrders(page, perPage, snapshotID)
var minOrderHash = common.HexToHash(minOrderHashHex)
getOrdersResponse, err := handler.app.GetOrders(perPage, minOrderHash)
if err != nil {
if _, ok := err.(core.ErrSnapshotNotFound); ok {
return nil, err
Expand Down
87 changes: 84 additions & 3 deletions common/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/0xProject/0x-mesh/zeroex"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/types"
)

// Stats is the return value for core.GetStats. Also used in the browser and RPC
Expand Down Expand Up @@ -42,9 +43,8 @@ type LatestBlock struct {
// GetOrdersResponse is the return value for core.GetOrders. Also used in the
// browser and RPC interface.
type GetOrdersResponse struct {
SnapshotID string `json:"snapshotID"`
SnapshotTimestamp time.Time `json:"snapshotTimestamp"`
OrdersInfos []*OrderInfo `json:"ordersInfos"`
Timestamp time.Time `json:"timestamp"`
OrdersInfos []*OrderInfo `json:"ordersInfos"`
}

// AddOrdersOpts is a set of options for core.AddOrders. Also used in the
Expand Down Expand Up @@ -96,3 +96,84 @@ func (o *OrderInfo) UnmarshalJSON(data []byte) error {
}
return nil
}

type OrderWithMetadata struct {
Hash common.Hash `json:"hash"`
ChainID *big.Int `json:"chainID"`
ExchangeAddress common.Address `json:"exchangeAddress"`
MakerAddress common.Address `json:"makerAddress"`
MakerAssetData []byte `json:"makerAssetData"`
MakerFeeAssetData []byte `json:"makerFeeAssetData"`
MakerAssetAmount *big.Int `json:"makerAssetAmount"`
MakerFee *big.Int `json:"makerFee"`
TakerAddress common.Address `json:"takerAddress"`
TakerAssetData []byte `json:"takerAssetData"`
TakerFeeAssetData []byte `json:"takerFeeAssetData"`
TakerAssetAmount *big.Int `json:"takerAssetAmount"`
TakerFee *big.Int `json:"takerFee"`
SenderAddress common.Address `json:"senderAddress"`
FeeRecipientAddress common.Address `json:"feeRecipientAddress"`
ExpirationTimeSeconds *big.Int `json:"expirationTimeSeconds"`
Salt *big.Int `json:"salt"`
Signature []byte `json:"signature"`
FillableTakerAssetAmount *big.Int `json:"fillableTakerAssetAmount"`
LastUpdated time.Time `json:"lastUpdated"`
// Was this order flagged for removal? Due to the possibility of block-reorgs, instead
// of immediately removing an order when FillableTakerAssetAmount becomes 0, we instead
// flag it for removal. After this order isn't updated for X time and has IsRemoved = true,
// the order can be permanently deleted.
IsRemoved bool `json:"isRemoved"`
// IsPinned indicates whether or not the order is pinned. Pinned orders are
// not removed from the database unless they become unfillable.
IsPinned bool `json:"isPinned"`
// JSON-encoded list of assetdatas contained in MakerAssetData. For non-MAP
// orders, the list contains only one element which is equal to MakerAssetData.
// For MAP orders, it contains each component assetdata.
ParsedMakerAssetData []*SingleAssetData `json:"parsedMakerAssetData"`
// Same as ParsedMakerAssetData but for MakerFeeAssetData instead of MakerAssetData.
ParsedMakerFeeAssetData []*SingleAssetData `json:"parsedMakerFeeAssetData"`
}

func (order OrderWithMetadata) SignedOrder() *zeroex.SignedOrder {
return &zeroex.SignedOrder{
Order: zeroex.Order{
ChainID: order.ChainID,
ExchangeAddress: order.ExchangeAddress,
MakerAddress: order.MakerAddress,
MakerAssetData: order.MakerAssetData,
MakerFeeAssetData: order.MakerFeeAssetData,
MakerAssetAmount: order.MakerAssetAmount,
MakerFee: order.MakerFee,
TakerAddress: order.TakerAddress,
TakerAssetData: order.TakerAssetData,
TakerFeeAssetData: order.TakerFeeAssetData,
TakerAssetAmount: order.TakerAssetAmount,
TakerFee: order.TakerFee,
SenderAddress: order.SenderAddress,
FeeRecipientAddress: order.FeeRecipientAddress,
ExpirationTimeSeconds: order.ExpirationTimeSeconds,
Salt: order.Salt,
},
Signature: order.Signature,
}
}

type SingleAssetData struct {
Address common.Address `json:"address"`
TokenID *big.Int `json:"tokenID"`
}

type MiniHeader struct {
Hash common.Hash `json:"hash"`
Parent common.Hash `json:"parent"`
Number *big.Int `json:"number"`
Timestamp time.Time `json:"timestamp"`
Logs []types.Log `json:"logs"`
}

type Metadata struct {
EthereumChainID int
MaxExpirationTime *big.Int
EthRPCRequestsSentInCurrentUTCDay int
StartOfCurrentUTCDay time.Time
}
7 changes: 7 additions & 0 deletions common/types/types_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package types
import (
"encoding/json"
"syscall/js"

"github.com/0xProject/0x-mesh/packages/browser/go/jsutil"
)

func (r GetOrdersResponse) JSValue() js.Value {
Expand Down Expand Up @@ -48,3 +50,8 @@ func (s Stats) JSValue() js.Value {
"ethRPCRateLimitExpiredRequests": s.EthRPCRateLimitExpiredRequests,
})
}

func (o OrderWithMetadata) JSValue() js.Value {
value, _ := jsutil.InefficientlyConvertToJS(o)
return value
}
5 changes: 5 additions & 0 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,8 @@ var (
const ParityFilterUnknownBlock = "One of the blocks specified in filter (fromBlock, toBlock or blockHash) cannot be found"

const GethFilterUnknownBlock = "unknown block"

var (
ZRXAssetData = common.Hex2Bytes("f47261b0000000000000000000000000871dd7c2b4b25e1aa18728e9d5f2af4c4e431f5c")
WETHAssetData = common.Hex2Bytes("f47261b00000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082")
)
Loading