From d3a8d3ce993a3a032108c01405165feb5e62b64d Mon Sep 17 00:00:00 2001 From: Doron Zavelevsky Date: Wed, 9 Aug 2023 14:15:43 +0300 Subject: [PATCH 1/3] fixed ID comparison that caused duplicate strategies --- src/chain-cache/ChainCache.ts | 4 ++-- tests/ChainCache.spec.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/chain-cache/ChainCache.ts b/src/chain-cache/ChainCache.ts index 93651f6..6d64ddd 100644 --- a/src/chain-cache/ChainCache.ts +++ b/src/chain-cache/ChainCache.ts @@ -458,7 +458,7 @@ export class ChainCache extends (EventEmitter as new () => TypedEventEmitter s.id !== strategy.id + (s) => !s.id.eq(strategy.id) ); strategies.push(strategy); this._strategiesByPair[key] = strategies; @@ -479,7 +479,7 @@ export class ChainCache extends (EventEmitter as new () => TypedEventEmitter s.id !== strategy.id + (s) => !s.id.eq(strategy.id) ); this._strategiesByPair[key] = strategies; this._removeStrategyOrders(strategy); diff --git a/tests/ChainCache.spec.ts b/tests/ChainCache.spec.ts index bdce94f..92dd51e 100644 --- a/tests/ChainCache.spec.ts +++ b/tests/ChainCache.spec.ts @@ -140,6 +140,17 @@ describe('ChainCache', () => { cache.applyBatchedUpdates(5, [], [], [], []); expect(affectedPairs).to.deep.equal([['abc', 'xyz']]); }); + it('should contain a single copy of a strategy that was updated', async () => { + const cache = new ChainCache(); + const encodedStrategy1_mod = { + ...encodedStrategy1, + id: BigNumber.from(encodedStrategy1.id.toString()), + }; + cache.addPair('abc', 'xyz', [encodedStrategy1]); + cache.applyBatchedUpdates(10, [], [], [encodedStrategy1_mod], []); + const strategies = await cache.getStrategiesByPair('abc', 'xyz'); + expect(strategies).to.have.length(1); + }); }); describe('cache miss', () => { it('getStrategiesByPair call miss handler when pair is not cached', async () => { From 30a2342efe29910458099b89ad13d5a62fe2e877 Mon Sep 17 00:00:00 2001 From: Doron Zavelevsky Date: Wed, 9 Aug 2023 14:32:12 +0300 Subject: [PATCH 2/3] incremented cache schema version since existing caches contain duplicate strategies --- src/chain-cache/ChainCache.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chain-cache/ChainCache.ts b/src/chain-cache/ChainCache.ts index 6d64ddd..5893b40 100644 --- a/src/chain-cache/ChainCache.ts +++ b/src/chain-cache/ChainCache.ts @@ -25,7 +25,7 @@ import { import { Logger } from '../common/logger'; const logger = new Logger('ChainCache.ts'); -const schemeVersion = 4; // bump this when the serialization format changes +const schemeVersion = 5; // bump this when the serialization format changes type PairToStrategiesMap = { [key: string]: EncodedStrategy[] }; type StrategyById = { [key: string]: EncodedStrategy }; From 02f69cbfe72da52d6af9478b42003284499f5428 Mon Sep 17 00:00:00 2001 From: Doron Zavelevsky Date: Wed, 9 Aug 2023 14:46:24 +0300 Subject: [PATCH 3/3] version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 486900f..12a8d90 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@bancor/carbon-sdk", "type": "module", "source": "src/index.ts", - "version": "0.0.80-DEV", + "version": "0.0.81-DEV", "description": "The SDK is a READ-ONLY tool, intended to facilitate working with Carbon contracts. It's a convenient wrapper around our matching algorithm, allowing programs and users get a ready to use transaction data that will allow them to manage strategies and fulfill trades", "main": "dist/index.js", "module": "dist/index.js",