mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-16 09:50:45 +00:00
parent
3ca2ff4fdb
commit
06d94520ba
3 changed files with 13 additions and 14 deletions
|
|
@ -332,22 +332,21 @@ func (s *stateObject) commitTrie(db Database) (int, error) {
|
||||||
return committed, err
|
return committed, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddBalance removes amount from c's balance.
|
// AddBalance adds amount to s's balance.
|
||||||
// It is used to add funds to the destination account of a transfer.
|
// It is used to add funds to the destination account of a transfer.
|
||||||
func (s *stateObject) AddBalance(amount *big.Int) {
|
func (s *stateObject) AddBalance(amount *big.Int) {
|
||||||
// EIP158: We must check emptiness for the objects such that the account
|
// EIP161: We must check emptiness for the objects such that the account
|
||||||
// clearing (0,0,0 objects) can take effect.
|
// clearing (0,0,0 objects) can take effect.
|
||||||
if amount.Sign() == 0 {
|
if amount.Sign() == 0 {
|
||||||
if s.empty() {
|
if s.empty() {
|
||||||
s.touch()
|
s.touch()
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.SetBalance(new(big.Int).Add(s.Balance(), amount))
|
s.SetBalance(new(big.Int).Add(s.Balance(), amount))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubBalance removes amount from c's balance.
|
// SubBalance removes amount from s's balance.
|
||||||
// It is used to remove funds from the origin account of a transfer.
|
// It is used to remove funds from the origin account of a transfer.
|
||||||
func (s *stateObject) SubBalance(amount *big.Int) {
|
func (s *stateObject) SubBalance(amount *big.Int) {
|
||||||
if amount.Sign() == 0 {
|
if amount.Sign() == 0 {
|
||||||
|
|
@ -409,7 +408,7 @@ func (s *stateObject) Code(db Database) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CodeSize returns the size of the contract code associated with this object,
|
// CodeSize returns the size of the contract code associated with this object,
|
||||||
// or zero if none. This methos is an almost mirror of Code, but uses a cache
|
// or zero if none. This method is an almost mirror of Code, but uses a cache
|
||||||
// inside the database to avoid loading codes seen recently.
|
// inside the database to avoid loading codes seen recently.
|
||||||
func (s *stateObject) CodeSize(db Database) int {
|
func (s *stateObject) CodeSize(db Database) int {
|
||||||
if s.code != nil {
|
if s.code != nil {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ type revision struct {
|
||||||
journalIndex int
|
journalIndex int
|
||||||
}
|
}
|
||||||
|
|
||||||
// StateDBs within the ethereum protocol are used to store anything
|
// StateDB structs within the ethereum protocol are used to store anything
|
||||||
// within the merkle trie. StateDBs take care of caching and storing
|
// within the merkle trie. StateDBs take care of caching and storing
|
||||||
// nested states. It's the general query interface to retrieve:
|
// nested states. It's the general query interface to retrieve:
|
||||||
// * Contracts
|
// * Contracts
|
||||||
|
|
@ -108,7 +108,7 @@ type AccountInfo struct {
|
||||||
StorageHash common.Hash
|
StorageHash common.Hash
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new state from a given trie.
|
// New creates a new state from a given trie.
|
||||||
func New(root common.Hash, db Database) (*StateDB, error) {
|
func New(root common.Hash, db Database) (*StateDB, error) {
|
||||||
tr, err := db.OpenTrie(root)
|
tr, err := db.OpenTrie(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -234,7 +234,7 @@ func (s *StateDB) Empty(addr common.Address) bool {
|
||||||
return so == nil || so.empty()
|
return so == nil || so.empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the balance from the given address or 0 if object not found
|
// GetBalance retrieves the balance from the given address or 0 if object not found
|
||||||
func (s *StateDB) GetBalance(addr common.Address) *big.Int {
|
func (s *StateDB) GetBalance(addr common.Address) *big.Int {
|
||||||
stateObject := s.getStateObject(addr)
|
stateObject := s.getStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
|
|
@ -553,7 +553,7 @@ func (s *StateDB) setStateObject(object *stateObject) {
|
||||||
s.stateObjects[object.Address()] = object
|
s.stateObjects[object.Address()] = object
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve a state object or create a new state object if nil.
|
// GetOrNewStateObject retrieves a state object or create a new state object if nil.
|
||||||
func (s *StateDB) GetOrNewStateObject(addr common.Address) *stateObject {
|
func (s *StateDB) GetOrNewStateObject(addr common.Address) *stateObject {
|
||||||
stateObject := s.getStateObject(addr)
|
stateObject := s.getStateObject(addr)
|
||||||
if stateObject == nil {
|
if stateObject == nil {
|
||||||
|
|
|
||||||
|
|
@ -144,9 +144,9 @@ func TestIntermediateLeaks(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestCopy tests that copying a statedb object indeed makes the original and
|
// TestCopy tests that copying a StateDB object indeed makes the original and
|
||||||
// the copy independent of each other. This test is a regression test against
|
// the copy independent of each other. This test is a regression test against
|
||||||
// https://github.com/XinFinOrg/XDPoSChain/pull/15549.
|
// https://github.com/ethereum/go-ethereum/pull/15549.
|
||||||
func TestCopy(t *testing.T) {
|
func TestCopy(t *testing.T) {
|
||||||
// Create a random state test to copy and modify "independently"
|
// Create a random state test to copy and modify "independently"
|
||||||
db := rawdb.NewMemoryDatabase()
|
db := rawdb.NewMemoryDatabase()
|
||||||
|
|
@ -707,11 +707,11 @@ func TestStateDBTransientStorage(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestDeleteCreateRevert tests a weird state transition corner case that we hit
|
// TestDeleteCreateRevert tests a weird state transition corner case that we hit
|
||||||
// while changing the internals of statedb. The workflow is that a contract is
|
// while changing the internals of StateDB. The workflow is that a contract is
|
||||||
// self destructed, then in a followup transaction (but same block) it's created
|
// self-destructed, then in a follow-up transaction (but same block) it's created
|
||||||
// again and the transaction reverted.
|
// again and the transaction reverted.
|
||||||
//
|
//
|
||||||
// The original statedb implementation flushed dirty objects to the tries after
|
// The original StateDB implementation flushed dirty objects to the tries after
|
||||||
// each transaction, so this works ok. The rework accumulated writes in memory
|
// each transaction, so this works ok. The rework accumulated writes in memory
|
||||||
// first, but the journal wiped the entire state object on create-revert.
|
// first, but the journal wiped the entire state object on create-revert.
|
||||||
func TestDeleteCreateRevert(t *testing.T) {
|
func TestDeleteCreateRevert(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue