Timestamps must be sorted prior to appending into thin history index (#411)

* Timestamps must be sorted prior to appending into thin history index

* Skip unstable test
This commit is contained in:
Andrew Ashikhmin 2020-03-27 16:46:34 +01:00 committed by GitHub
parent a364cfded6
commit 435d56e2fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View File

@ -318,6 +318,8 @@ func waitForAccounts(wantAccounts []accounts.Account, ks *KeyStore) error {
// TestUpdatedKeyfileContents tests that updating the contents of a keystore file
// is noticed by the watcher, and the account cache is updated accordingly
func TestUpdatedKeyfileContents(t *testing.T) {
t.Skip("This test is unstable")
t.Parallel()
// Create a temporary kesytore to test with

View File

@ -379,7 +379,17 @@ func (m *mutation) Commit() (uint64, error) {
m.mu.Lock()
defer m.mu.Unlock()
for timestamp, changes := range m.accountChangeSetByBlock {
// we need sorted timestamps for thin history index
accountTimestamps := make([]uint64, 0)
for ts := range m.accountChangeSetByBlock {
accountTimestamps = append(accountTimestamps, ts)
}
sort.Slice(accountTimestamps, func(i, j int) bool { return accountTimestamps[i] < accountTimestamps[j] })
for _, timestamp := range accountTimestamps {
changes := m.accountChangeSetByBlock[timestamp]
sort.Sort(changes)
if debug.IsThinHistory() {
changedKeys := changes.ChangedKeys()
for k := range changedKeys {
@ -393,7 +403,7 @@ func (m *mutation) Commit() (uint64, error) {
m.puts.Set(dbutils.AccountsHistoryBucket, key, *index)
}
}
sort.Sort(changes)
var (
dat []byte
err error
@ -410,12 +420,20 @@ func (m *mutation) Commit() (uint64, error) {
m.puts.Set(dbutils.AccountChangeSetBucket, dbutils.EncodeTimestamp(timestamp), dat)
}
for timestamp, changes := range m.storageChangeSetByBlock {
storageTimestamps := make([]uint64, 0)
for ts := range m.storageChangeSetByBlock {
storageTimestamps = append(storageTimestamps, ts)
}
sort.Slice(storageTimestamps, func(i, j int) bool { return storageTimestamps[i] < storageTimestamps[j] })
for _, timestamp := range storageTimestamps {
changes := m.storageChangeSetByBlock[timestamp]
sort.Sort(changes)
var (
dat []byte
err error
)
sort.Sort(changes)
if debug.IsThinHistory() {
changedKeys := changes.ChangedKeys()