Skip to content

Commit

Permalink
Merge pull request #3941 from 2opremio/merge-master
Browse files Browse the repository at this point in the history
Merge master into amm branch
  • Loading branch information
2opremio authored Sep 20, 2021
2 parents 9e69521 + 2aac2a9 commit 588ce03
Show file tree
Hide file tree
Showing 43 changed files with 503 additions and 301 deletions.
18 changes: 12 additions & 6 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
"options": {
"cwd": "${workspaceRoot}"
},
"tasks": [{
"taskName": "test all",
"isWatching": false,
"args": ["test", "./..."]
}]
}
"tasks": [
{
"label": "test all",
"type": "shell",
"args": [
"test",
"./..."
],
"problemMatcher": []
}
]
}
33 changes: 19 additions & 14 deletions exp/orderbook/dfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,21 @@ type searchState interface {
) (xdr.Asset, xdr.Int64, error)
}

func contains(list []string, want string) bool {
for i := 0; i < len(list); i++ {
if list[i] == want {
return true
}
}
return false
}

func dfs(
ctx context.Context,
state searchState,
maxPathLength int,
visited []xdr.Asset,
visitedAssets []xdr.Asset,
visitedAssetStrings []string,
remainingTerminalNodes int,
currentAssetString string,
currentAsset xdr.Asset,
Expand All @@ -73,31 +83,25 @@ func dfs(
if err := ctx.Err(); err != nil {
return err
}
if currentAssetAmount <= 0 {
return nil
}
for _, asset := range visited {
if asset.Equals(currentAsset) {
return nil
}
}

updatedVisitedList := append(visited, currentAsset)
updatedVisitedAssets := append(visitedAssets, currentAsset)
updatedVisitedStrings := append(visitedAssetStrings, currentAssetString)

if state.isTerminalNode(currentAssetString, currentAssetAmount) {
state.appendToPaths(
updatedVisitedList,
updatedVisitedAssets,
currentAssetString,
currentAssetAmount,
)
remainingTerminalNodes--
}
// abort search if we've visited all destination nodes or if we've exceeded maxPathLength
if remainingTerminalNodes == 0 || len(updatedVisitedList) > maxPathLength {
if remainingTerminalNodes == 0 || len(updatedVisitedStrings) > maxPathLength {
return nil
}

for nextAssetString, offers := range state.edges(currentAssetString) {
if len(offers) == 0 {
if len(offers) == 0 || contains(visitedAssetStrings, nextAssetString) {
continue
}

Expand All @@ -113,7 +117,8 @@ func dfs(
ctx,
state,
maxPathLength,
updatedVisitedList,
updatedVisitedAssets,
updatedVisitedStrings,
remainingTerminalNodes,
nextAssetString,
nextAsset,
Expand Down
2 changes: 2 additions & 0 deletions exp/orderbook/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ func (graph *OrderBookGraph) FindPaths(
searchState,
maxPathLength,
[]xdr.Asset{},
[]string{},
len(sourceAssets),
destinationAssetString,
destinationAsset,
Expand Down Expand Up @@ -416,6 +417,7 @@ func (graph *OrderBookGraph) FindFixedPaths(
searchState,
maxPathLength,
[]xdr.Asset{},
[]string{},
len(destinationAssets),
sourceAsset.String(),
sourceAsset,
Expand Down
2 changes: 1 addition & 1 deletion exp/services/recoverysigner/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SUDO := $(shell docker version >/dev/null 2>&1 || echo "sudo")
# If TAG is not provided set default value
TAG ?= stellar/recoverysigner:$(shell git rev-parse --short HEAD)$(and $(shell git status -s),-dirty-$(shell id -u -n))
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
BUILD_DATE := $(shell date --utc --rfc-3339=seconds)
BUILD_DATE := $(shell date -u +%FT%TZ)

docker-build:
cd ../../../ && \
Expand Down
2 changes: 1 addition & 1 deletion exp/services/webauth/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SUDO := $(shell docker version >/dev/null 2>&1 || echo "sudo")
# If TAG is not provided set default value
TAG ?= stellar/webauth:$(shell git rev-parse --short HEAD)$(and $(shell git status -s),-dirty-$(shell id -u -n))
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
BUILD_DATE := $(shell date --utc --rfc-3339=seconds)
BUILD_DATE := $(shell date -u +%FT%TZ)

docker-build:
cd ../../../ && \
Expand Down
4 changes: 2 additions & 2 deletions go.list
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ github.com/spf13/viper v0.0.0-20150621231900-db7ff930a189
github.com/stellar/go
github.com/stellar/go-xdr v0.0.0-20201028102745-f80a23dac78a
github.com/stellar/throttled v2.2.3-0.20190823235211-89d75816f59d+incompatible
github.com/stretchr/objx v0.1.1
github.com/stretchr/testify v1.6.1
github.com/stretchr/objx v0.3.0
github.com/stretchr/testify v1.7.0
github.com/tyler-smith/go-bip39 v0.0.0-20180618194314-52158e4697b8
github.com/valyala/bytebufferpool v1.0.0
github.com/valyala/fasthttp v0.0.0-20170109085056-0a7f0a797cd6
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ require (
github.com/spf13/viper v0.0.0-20150621231900-db7ff930a189
github.com/stellar/go-xdr v0.0.0-20201028102745-f80a23dac78a
github.com/stellar/throttled v2.2.3-0.20190823235211-89d75816f59d+incompatible
github.com/stretchr/testify v1.6.1
github.com/stretchr/objx v0.3.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/tyler-smith/go-bip39 v0.0.0-20180618194314-52158e4697b8
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v0.0.0-20170109085056-0a7f0a797cd6 // indirect
Expand Down
7 changes: 5 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,16 @@ github.com/stellar/go-xdr v0.0.0-20201028102745-f80a23dac78a/go.mod h1:yoxyU/M8n
github.com/stellar/throttled v2.2.3-0.20190823235211-89d75816f59d+incompatible h1:jMXXAcz6xTarGDQ4VtVbtERogcmDQw4RaE85Cr9CgoQ=
github.com/stellar/throttled v2.2.3-0.20190823235211-89d75816f59d+incompatible/go.mod h1:7CJ23pXirXBJq45DqvO6clzTEGM/l1SfKrgrzLry8b4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tyler-smith/go-bip39 v0.0.0-20180618194314-52158e4697b8 h1:g3yQGZK+G6dfF/mw/SOwsTMzUVkpT4hB8pHxpbTXkKw=
github.com/tyler-smith/go-bip39 v0.0.0-20180618194314-52158e4697b8/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
Expand Down
5 changes: 5 additions & 0 deletions keypair/from_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
"github.com/stretchr/testify/assert"
)

func TestFromAddress_Hint(t *testing.T) {
kp := MustParseAddress("GAYUB4KATGTUZEGUMJEOZDPPWM4MQLHCIKC4T55YSXHN234WI6BJMIY2")
assert.Equal(t, [4]byte{0x96, 0x47, 0x82, 0x96}, kp.Hint())
}

func TestFromAddress_Equal(t *testing.T) {
// A nil FromAddress.
var kp0 *FromAddress
Expand Down
6 changes: 6 additions & 0 deletions keypair/full_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import (
"github.com/stretchr/testify/assert"
)

func TestFull_Hint(t *testing.T) {
kp := MustParseFull("SBFGFF27Y64ZUGFAIG5AMJGQODZZKV2YQKAVUUN4HNE24XZXD2OEUVUP")
assert.Equal(t, [4]byte{0x96, 0x47, 0x82, 0x96}, kp.Hint())
assert.Equal(t, [4]byte{0x96, 0x47, 0x82, 0x96}, kp.FromAddress().Hint())
}

func TestFull_Equal(t *testing.T) {
// A nil Full.
var kp0 *Full
Expand Down
2 changes: 1 addition & 1 deletion services/friendbot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SUDO := $(shell docker version >/dev/null 2>&1 || echo "sudo")
# If TAG is not provided set default value
TAG ?= stellar/friendbot:$(shell git rev-parse --short HEAD)$(and $(shell git status -s),-dirty-$(shell id -u -n))
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
BUILD_DATE := $(shell date --utc --rfc-3339=seconds)
BUILD_DATE := $(shell date -u +%FT%TZ)

docker-build:
cd ../../ && \
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/docker/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SUDO := $(shell docker version >/dev/null 2>&1 || echo "sudo")

# https://github.com/opencontainers/image-spec/blob/master/annotations.md
BUILD_DATE := $(shell date --utc --rfc-3339=seconds)
BUILD_DATE := $(shell date -u +%FT%TZ)

TAG ?= stellar/stellar-horizon:$(VERSION)

Expand Down
4 changes: 2 additions & 2 deletions services/horizon/docker/verify-range/dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ echo "deb https://apt.stellar.org $(lsb_release -cs) stable" | sudo tee -a /etc/
apt-get update
apt-get install -y stellar-core=${STELLAR_CORE_VERSION}

wget https://dl.google.com/go/go1.16.5.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.16.5.linux-amd64.tar.gz
wget https://dl.google.com/go/go1.17.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.17.linux-amd64.tar.gz

# configure postgres
service postgresql start
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/docker/verify-range/start
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ git pull origin
if [ ! -z "$BRANCH" ]; then
git checkout $BRANCH
fi
git log -1
git log -1 --pretty=oneline

function alter_tables_unlogged() {
# UNLOGGED for performance reasons (order is important because some tables reference others)
Expand Down
6 changes: 1 addition & 5 deletions services/horizon/internal/action_offers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,8 @@ func TestOfferActions_Show(t *testing.T) {
LastModifiedLedger: uint32(4),
}

batch := q.NewOffersBatchInsertBuilder(3)
err = batch.Add(ctx, eurOffer)
err = q.UpsertOffers(ctx, []history.Offer{eurOffer, usdOffer})
ht.Assert.NoError(err)
err = batch.Add(ctx, usdOffer)
ht.Assert.NoError(err)
ht.Assert.NoError(batch.Exec(ctx))

w := ht.Get("/offers")
if ht.Assert.Equal(200, w.Code) {
Expand Down
21 changes: 3 additions & 18 deletions services/horizon/internal/actions/offer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,8 @@ func TestGetOfferByIDHandler(t *testing.T) {
}, 0, 0, 0, 0, 0)
tt.Assert.NoError(err)

batch := q.NewOffersBatchInsertBuilder(0)
err = batch.Add(tt.Ctx, eurOffer)
err = q.UpsertOffers(tt.Ctx, []history.Offer{eurOffer, usdOffer})
tt.Assert.NoError(err)
err = batch.Add(tt.Ctx, usdOffer)
tt.Assert.NoError(err)
tt.Assert.NoError(batch.Exec(tt.Ctx))

for _, testCase := range []struct {
name string
Expand Down Expand Up @@ -200,14 +196,8 @@ func TestGetOffersHandler(t *testing.T) {
}, 0, 0, 0, 0, 0)
tt.Assert.NoError(err)

batch := q.NewOffersBatchInsertBuilder(0)
err = batch.Add(tt.Ctx, eurOffer)
tt.Assert.NoError(err)
err = batch.Add(tt.Ctx, twoEurOffer)
err = q.UpsertOffers(tt.Ctx, []history.Offer{eurOffer, twoEurOffer, usdOffer})
tt.Assert.NoError(err)
err = batch.Add(tt.Ctx, usdOffer)
tt.Assert.NoError(err)
tt.Assert.NoError(batch.Exec(tt.Ctx))

t.Run("No filter", func(t *testing.T) {
records, err := handler.GetResourcePage(
Expand Down Expand Up @@ -477,13 +467,8 @@ func TestGetAccountOffersHandler(t *testing.T) {
q := &history.Q{tt.HorizonSession()}
handler := GetAccountOffersHandler{}

batch := q.NewOffersBatchInsertBuilder(0)
err := batch.Add(tt.Ctx, eurOffer)
err = batch.Add(tt.Ctx, twoEurOffer)
tt.Assert.NoError(err)
err = batch.Add(tt.Ctx, usdOffer)
err := q.UpsertOffers(tt.Ctx, []history.Offer{eurOffer, twoEurOffer, usdOffer})
tt.Assert.NoError(err)
tt.Assert.NoError(batch.Exec(tt.Ctx))

records, err := handler.GetResourcePage(
httptest.NewRecorder(),
Expand Down
7 changes: 1 addition & 6 deletions services/horizon/internal/actions/orderbook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,7 @@ func TestOrderbookGetResource(t *testing.T) {
}

assert.NoError(t, q.TruncateTables(tt.Ctx, []string{"offers"}))

batch := q.NewOffersBatchInsertBuilder(0)
for _, offer := range offers {
assert.NoError(t, batch.Add(tt.Ctx, offer))
}
assert.NoError(t, batch.Exec(tt.Ctx))
assert.NoError(t, q.UpsertOffers(tt.Ctx, offers))

assert.NoError(t, q.BeginTx(&sql.TxOptions{
Isolation: sql.LevelRepeatableRead,
Expand Down
Loading

0 comments on commit 588ce03

Please sign in to comment.