From b380382196483e1dbed554bb6471b93b36c98ddc Mon Sep 17 00:00:00 2001 From: cohcho Date: Tue, 3 Mar 2020 07:52:05 +0000 Subject: [PATCH] store_share: modify compare_share to avoid fail compare_share() doesn't implement strict ordering store_share() uses MDB_APPENDDUP to avoid problem with compare_share MDB_APPENDDUP may fail since the following pair of valid shares can't added in specified order: 1. {share1, share2 | (share1.timestamp < share2.timestamp) && (share1.address > share2.address)} 2. {share1, share2 | (share1.timestamp > share2.timestamp) && (share1.address == share2.address)} If there is no plan to avoid usage of MDB_APPENDDUP in store_share() then compare_share() can be modified to use only timestamp field thus avoid MDB_APPENDDUP fail in the first case. --- src/pool.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pool.c b/src/pool.c index ad70169..6c5f36b 100644 --- a/src/pool.c +++ b/src/pool.c @@ -337,11 +337,7 @@ compare_share(const MDB_val *a, const MDB_val *b) { const share_t *va = (const share_t*) a->mv_data; const share_t *vb = (const share_t*) b->mv_data; - int sc = strcmp(va->address, vb->address); - if (sc == 0) - return (va->timestamp < vb->timestamp) ? -1 : 1; - else - return sc; + return (va->timestamp < vb->timestamp) ? -1 : 1; } static int