diff --git a/core/collector.go b/core/collector.go index 88db4d7..e63f0e8 100644 --- a/core/collector.go +++ b/core/collector.go @@ -276,7 +276,7 @@ func (engine *rpcCollector) fetchInitialDelegationState(ctx context.Context, del balanceInfo, err := engine.fetchContractInitialBalanceInfo(ctx, address, blockWithMinimumId, lastBlockInCycle) if err != nil { - slog.Debug("failed to fetch contract balance info", "address", address.String(), "error", err) + slog.Warn("failed to fetch contract balance info", "address", address.String(), "error", err) mtx.Lock() defer mtx.Unlock() diff --git a/core/collector_test.go b/core/collector_test.go index 00fcf68..32c3cf8 100644 --- a/core/collector_test.go +++ b/core/collector_test.go @@ -17,8 +17,8 @@ var ( defaultCtx context.Context = context.Background() ) -func getTransport() *test.TestTransport { - transport, err := test.NewTestTransport(http.DefaultTransport, "../test/data/745", "../test/data/745.gob.lz4") +func getTransport(path string) *test.TestTransport { + transport, err := test.NewTestTransport(http.DefaultTransport, path, path+".gob.lz4") if err != nil { panic(err) } @@ -28,7 +28,7 @@ func getTransport() *test.TestTransport { func TestGetActiveDelegates(t *testing.T) { assert := assert.New(t) - collector, err := newRpcCollector(defaultCtx, []string{"https://eu.rpc.tez.capital/", "https://rpc.tzkt.io/mainnet/"}, getTransport()) + collector, err := newRpcCollector(defaultCtx, []string{"https://eu.rpc.tez.capital/", "https://rpc.tzkt.io/mainnet/"}, getTransport("../test/data/745")) assert.Nil(err) delegates, err := collector.GetActiveDelegatesFromCycle(defaultCtx, 745) @@ -38,15 +38,38 @@ func TestGetActiveDelegates(t *testing.T) { func TestGetDelegationStateNoStaking(t *testing.T) { assert := assert.New(t) + debug.SetMaxThreads(1000000) + // cycle 745 cycle := int64(745) + collector, err := newRpcCollector(defaultCtx, []string{"https://eu.rpc.tez.capital/", "https://rpc.tzkt.io/mainnet/"}, getTransport("../test/data/745")) + assert.Nil(err) - debug.SetMaxThreads(1000000) + delegates, err := collector.GetActiveDelegatesFromCycle(defaultCtx, cycle) + assert.Nil(err) + + err = runInParallel(defaultCtx, delegates, constants.OGUN_DELEGATE_FETCH_BATCH_SIZE, func(ctx context.Context, addr tezos.Address, mtx *sync.RWMutex) bool { + delegate, err := collector.GetDelegateFromCycle(defaultCtx, cycle, addr) + if err != nil { + assert.Nil(err) + return true + } - collector, err := newRpcCollector(defaultCtx, []string{"https://eu.rpc.tez.capital/", "https://rpc.tzkt.io/mainnet/"}, getTransport()) + _, err = collector.GetDelegationState(defaultCtx, delegate, 745) + if err != nil && err != constants.ErrDelegateHasNoMinimumDelegatedBalance { + assert.Nil(err) + return true + } + return false + }) assert.Nil(err) - delegates, err := collector.GetActiveDelegatesFromCycle(defaultCtx, cycle) + // cycle 746 + cycle = int64(745) + collector, err = newRpcCollector(defaultCtx, []string{"https://eu.rpc.tez.capital/", "https://rpc.tzkt.io/mainnet/"}, getTransport("../test/data/746")) + assert.Nil(err) + + delegates, err = collector.GetActiveDelegatesFromCycle(defaultCtx, cycle) assert.Nil(err) err = runInParallel(defaultCtx, delegates, constants.OGUN_DELEGATE_FETCH_BATCH_SIZE, func(ctx context.Context, addr tezos.Address, mtx *sync.RWMutex) bool { diff --git a/go.mod b/go.mod index a32697d..64071ce 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,11 @@ require ( gorm.io/gorm v1.25.10 ) -require github.com/gorilla/websocket v1.4.2 // indirect +require ( + github.com/gorilla/websocket v1.4.2 // indirect + github.com/philhofer/fwd v1.1.2 // indirect + github.com/tinylib/msgp v1.1.9 // indirect +) require ( github.com/andybalholm/brotli v1.1.0 // indirect @@ -39,7 +43,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasthttp v1.54.0 // indirect + github.com/valyala/fasthttp v1.55.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect golang.org/x/crypto v0.24.0 // indirect golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect diff --git a/go.sum b/go.sum index 3234302..b10dbb5 100644 --- a/go.sum +++ b/go.sum @@ -51,6 +51,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw= +github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0= github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ= github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -67,12 +69,14 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tinylib/msgp v1.1.9 h1:SHf3yoO2sGA0veCJeCBYLHuttAVFHGm2RHgNodW7wQU= +github.com/tinylib/msgp v1.1.9/go.mod h1:BCXGB54lDD8qUEPmiG0cQQUANC4IUQyB2ItS2UDlO/k= github.com/trilitech/tzgo v1.19.7-0.20240615084153-32cae2559148 h1:3IAI5Ora7g8SrwzpA62hblsjE24y08M6OmiML3xjhqE= github.com/trilitech/tzgo v1.19.7-0.20240615084153-32cae2559148/go.mod h1:YU8inIqQeOmGKAs4+t/l6aQ1SYWom1SMb3mpRnHj/MM= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v1.54.0 h1:cCL+ZZR3z3HPLMVfEYVUMtJqVaui0+gu7Lx63unHwS0= -github.com/valyala/fasthttp v1.54.0/go.mod h1:6dt4/8olwq9QARP/TDuPmWyWcl4byhpvTJ4AAtcz+QM= +github.com/valyala/fasthttp v1.55.0 h1:Zkefzgt6a7+bVKHnu/YaYSOPfNYNisSVBo/unVCf8k8= +github.com/valyala/fasthttp v1.55.0/go.mod h1:NkY9JtkrpPKmgwV3HTaS2HWaJss9RSIsRVfcxxoHiOM= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= diff --git a/test/cache-builder/readme.md b/test/cache-builder/readme.md new file mode 100644 index 0000000..a8bd025 --- /dev/null +++ b/test/cache-builder/readme.md @@ -0,0 +1 @@ +go run test/cache-builder/main.go test/data/746/ \ No newline at end of file diff --git a/test/data/746.gob.lz4 b/test/data/746.gob.lz4 new file mode 100644 index 0000000..cf2f20c Binary files /dev/null and b/test/data/746.gob.lz4 differ