swarm icon indicating copy to clipboard operation
swarm copied to clipboard

Add a timestamp to balances and cheques

Open holisticode opened this issue 5 years ago • 9 comments

In Swap, we store balances and cheques in a StateStore.

If a balance or a cheque never gets settled, it will stay forever there. It also means that over time, we might get entries which get stale because the peer disappeared or we dropped it and we don't communicate with it.

It is rather a difficult problem to resolve what to do with these entries.

Having at least a timestamp helps identify how old a LastExchanged entry is, in order to help evaluate what to do with it.

In the future, even an archiving of "older" balances or cheques might be considered.

holisticode avatar Jul 24 '19 14:07 holisticode

@janos 's opinion highly welcomed

holisticode avatar Dec 18 '19 14:12 holisticode

I would consider this a very reasonable requirement, even very important.

janos avatar Dec 18 '19 15:12 janos

Actually I wanted your opinion on archiving entries, and how to do it, because you have extensively investigated LevelDB.

However, I now realize that this ticket is about adding a timestamp only, to be able to analyze balance and cheques data. We can then decide about archiving later.

holisticode avatar Dec 18 '19 15:12 holisticode

I see, different prefixes for archived keys and regular ones in StateStore is the way to go. There already is the Iterate method with prefix and moving data from one key to anther can be done in a batch.

For optimization, there could be even a timestamp "index", prefixed keys ordered by timestamps so that iteration on discovering staled balances and cheques would be less costly.

janos avatar Dec 18 '19 15:12 janos

few questions here:

  • is there a size limit to each store?
  • would we be able to tell if the data we need is archived? how?

mortelli avatar Dec 18 '19 19:12 mortelli

  • would we be able to tell if the data we need is archived? how?

=>

different prefixes for archived keys and regular ones in StateStore is the way to go

holisticode avatar Dec 18 '19 19:12 holisticode

maybe i'm not following here, but:

suppose i want a cheque for peer p. how do i know if this is stored in the regular store or the archived one? wouldn't the keys be named by date?

mortelli avatar Dec 18 '19 19:12 mortelli

You'd probably first search the "live" keys, and if not found, the "archived" ones.

But keep in mind that we did not decide yet if we are going to archive at all. That's why we need the timestamps in order to make informed guesses :)

holisticode avatar Dec 18 '19 19:12 holisticode

We should see what kind of queries there would be. All cheques and balances (live and archived) can be under a single key prefix, but that they contain a field to mark them as archived. And to keep an "index" by their timestamps for iterations by their age.

I think that it would be good to know how archived entries would be handled before organising the data.

janos avatar Dec 19 '19 11:12 janos