Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#9927] Fast blocks sync after being offline #9942

Merged
merged 1 commit into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 8 additions & 7 deletions src/status_im/ethereum/subscriptions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
{:db (assoc-in db [:ethereum/subscriptions id] handler)})

(fx/defn new-block
[{:keys [db] :as cofx} historical? block-number accounts]
[{:keys [db] :as cofx} historical? block-number accounts transactions-per-account]
(let [{:keys [:wallet/all-tokens]} db
chain (ethereum/chain-keyword db)
chain-tokens (into {} (map (juxt :address identity)
(tokens/tokens-for all-tokens chain)))]
(log/debug "[wallet-subs] new-block"
"accounts" accounts
"block" block-number)
"block" block-number
"transactions-per-account" transactions-per-account)
(fx/merge cofx
(cond-> {}
(not historical?)
Expand All @@ -41,10 +42,10 @@
;;NOTE only get transfers if the new block contains some
;; from/to one of the multiaccount accounts
(not-empty accounts)
(assoc :transactions/get-transfers-from-block
(assoc :transactions/get-transfers
{:chain-tokens chain-tokens
:addresses accounts
:block block-number
:before-block block-number
:historical? historical?}))
(transactions/check-watched-transactions))))

Expand Down Expand Up @@ -91,12 +92,12 @@
:historical? true}}))

(fx/defn new-wallet-event
[cofx {:keys [type blockNumber accounts] :as event}]
[cofx {:keys [type blockNumber accounts newTransactions] :as event}]
(log/debug "[wallet-subs] new-wallet-event"
"event-type" type)
(case type
"newblock" (new-block cofx false blockNumber accounts)
"history" (new-block cofx true blockNumber accounts)
"newblock" (new-block cofx false blockNumber accounts newTransactions)
"history" (new-block cofx true blockNumber accounts nil)
"reorg" (reorg cofx event)
"recent-history-fetching" (recent-history-fetching-started cofx accounts)
"recent-history-ready" (recent-history-fetching-ended cofx event)
Expand Down
28 changes: 15 additions & 13 deletions src/status_im/ethereum/transactions/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -231,26 +231,30 @@

(re-frame/reg-fx
:transactions/get-transfers
(fn [{:keys [chain-tokens addresses before-block page-size]
(fn [{:keys [chain-tokens addresses before-block page-size
transactions-per-address]
:as params
:or {page-size 0}}]
:or {page-size 20}}]
{:pre [(cljs.spec.alpha/valid?
(cljs.spec.alpha/coll-of string?)
addresses)]}
(log/debug "[transactions] get-transfers"
"addresses" addresses
"block" before-block
"page-size" page-size)
"page-size" page-size
"transactions-per-address" transactions-per-address)
(when before-block
(doseq [address addresses]
(json-rpc/call
{:method "wallet_getTransfersByAddress"
:params [address (encode/uint before-block) (encode/uint page-size)]
:on-success #(re-frame/dispatch
[::new-transfers
(enrich-transfers chain-tokens %)
(assoc params :address address)])
:on-error #(re-frame/dispatch [::tx-fetching-failed address])})))))
(let [page-size (or (get transactions-per-address address)
page-size)]
(json-rpc/call
{:method "wallet_getTransfersByAddress"
:params [address (encode/uint before-block) (encode/uint page-size)]
:on-success #(re-frame/dispatch
[::new-transfers
(enrich-transfers chain-tokens %)
(assoc params :address address)])
:on-error #(re-frame/dispatch [::tx-fetching-failed address])}))))))

(fx/defn initialize
[{:keys [db]} addresses]
Expand All @@ -261,7 +265,6 @@
{:transactions/get-transfers
{:chain-tokens chain-tokens
:addresses (map eip55/address->checksum addresses)
:page-size 20
:historical? true}}))

(fx/defn fetch-more-tx
Expand All @@ -282,6 +285,5 @@
{:chain-tokens chain-tokens
:addresses [address]
:before-block min-known-block
:page-size 20
:historical? true}}
(tx-fetching-in-progress [address]))))
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im",
"repo": "status-go",
"version": "v0.41.0",
"commit-sha1": "8931b14c4e40261e6161a3c776bf16cc0fdd1f3a",
"src-sha256": "16r3xbzhh3fljpx11yahm1r5xh4cyvggy5avg6smkpw9m93cb6f7"
"version": "v0.41.1",
"commit-sha1": "c2f22f1fbc73e68b8d82370c4645c786739fb40b",
"src-sha256": "038paj2gwdih154nnafcxc3w02x9p21ifkv1g9k2rr1ac0ypainb"
}