mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
core, triedb/pathdb: bail out error if write state history fails
This commit is contained in:
parent
79e8870e34
commit
0d1f0f5a8b
3 changed files with 21 additions and 10 deletions
|
|
@ -258,13 +258,21 @@ func ReadStateHistory(db ethdb.AncientReaderOp, id uint64) ([]byte, []byte, []by
|
||||||
// WriteStateHistory writes the provided state history to database. Compute the
|
// WriteStateHistory writes the provided state history to database. Compute the
|
||||||
// position of state history in freezer by minus one since the id of first state
|
// position of state history in freezer by minus one since the id of first state
|
||||||
// history starts from one(zero for initial state).
|
// history starts from one(zero for initial state).
|
||||||
func WriteStateHistory(db ethdb.AncientWriter, id uint64, meta []byte, accountIndex []byte, storageIndex []byte, accounts []byte, storages []byte) {
|
func WriteStateHistory(db ethdb.AncientWriter, id uint64, meta []byte, accountIndex []byte, storageIndex []byte, accounts []byte, storages []byte) error {
|
||||||
db.ModifyAncients(func(op ethdb.AncientWriteOp) error {
|
_, err := db.ModifyAncients(func(op ethdb.AncientWriteOp) error {
|
||||||
op.AppendRaw(stateHistoryMeta, id-1, meta)
|
if err := op.AppendRaw(stateHistoryMeta, id-1, meta); err != nil {
|
||||||
op.AppendRaw(stateHistoryAccountIndex, id-1, accountIndex)
|
return err
|
||||||
op.AppendRaw(stateHistoryStorageIndex, id-1, storageIndex)
|
}
|
||||||
op.AppendRaw(stateHistoryAccountData, id-1, accounts)
|
if err := op.AppendRaw(stateHistoryAccountIndex, id-1, accountIndex); err != nil {
|
||||||
op.AppendRaw(stateHistoryStorageData, id-1, storages)
|
return err
|
||||||
return nil
|
}
|
||||||
|
if err := op.AppendRaw(stateHistoryStorageIndex, id-1, storageIndex); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := op.AppendRaw(stateHistoryAccountData, id-1, accounts); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return op.AppendRaw(stateHistoryStorageData, id-1, storages)
|
||||||
})
|
})
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -231,6 +231,8 @@ func (dl *diskLayer) commit(bottom *diffLayer, force bool) (*diskLayer, error) {
|
||||||
oldest uint64
|
oldest uint64
|
||||||
)
|
)
|
||||||
if dl.db.freezer != nil {
|
if dl.db.freezer != nil {
|
||||||
|
// Bail out with an error if writing the state history fails.
|
||||||
|
// This can happen, for example, if the device is full.
|
||||||
err := writeHistory(dl.db.freezer, bottom)
|
err := writeHistory(dl.db.freezer, bottom)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -542,8 +542,9 @@ func writeHistory(writer ethdb.AncientWriter, dl *diffLayer) error {
|
||||||
indexSize := common.StorageSize(len(accountIndex) + len(storageIndex))
|
indexSize := common.StorageSize(len(accountIndex) + len(storageIndex))
|
||||||
|
|
||||||
// Write history data into five freezer table respectively.
|
// Write history data into five freezer table respectively.
|
||||||
rawdb.WriteStateHistory(writer, dl.stateID(), history.meta.encode(), accountIndex, storageIndex, accountData, storageData)
|
if err := rawdb.WriteStateHistory(writer, dl.stateID(), history.meta.encode(), accountIndex, storageIndex, accountData, storageData); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
historyDataBytesMeter.Mark(int64(dataSize))
|
historyDataBytesMeter.Mark(int64(dataSize))
|
||||||
historyIndexBytesMeter.Mark(int64(indexSize))
|
historyIndexBytesMeter.Mark(int64(indexSize))
|
||||||
historyBuildTimeMeter.UpdateSince(start)
|
historyBuildTimeMeter.UpdateSince(start)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue