forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 2
access list #8
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
Open
scf0220
wants to merge
4
commits into
master
Choose a base branch
from
eip_accessList
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
access list #8
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,17 +18,94 @@ package state | |
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"math/big" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/ethdb/leveldb" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/metrics" | ||
"github.com/ethereum/go-ethereum/rlp" | ||
"io" | ||
"math/big" | ||
"sync" | ||
"time" | ||
) | ||
|
||
var ( | ||
// AccessListDB: store generated data(key:blockNumber value:access list) | ||
AccessListDB, _ = leveldb.New("./accessList_eth", 512, 512, "") | ||
|
||
// BlockNumToAccessList: Preprocess the access list corresponding to the block | ||
BlockNumToAccessList = make(map[int][]common.AccessList, 0) | ||
) | ||
|
||
func init() { | ||
if common.CalAccessList { | ||
return | ||
} | ||
|
||
// import block from 800w to 820w | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 800w to 820w --> 8M to 8.2M |
||
start := 8000000 | ||
end := 8200000 | ||
|
||
log.Info("preLoad access list", "from", start, "to", end) | ||
for index := start; index <= end; index++ { | ||
data, err := AccessListDB.Get(common.Uint64ToBytes(uint64(index))) | ||
list := make([]common.AccessList, 0) | ||
if len(data) == 0 || err != nil { | ||
|
||
} else { | ||
if err := json.Unmarshal(data, &list); err != nil { | ||
panic(err) | ||
} | ||
} | ||
BlockNumToAccessList[index] = list | ||
} | ||
log.Info("preLoad access list", "size", len(BlockNumToAccessList)) | ||
} | ||
|
||
type OriginStorage struct { | ||
Data map[common.Address]Storage | ||
mu sync.Mutex | ||
} | ||
|
||
func NewOriginStorage() *OriginStorage { | ||
return &OriginStorage{ | ||
Data: make(map[common.Address]Storage, 0), | ||
} | ||
} | ||
|
||
func (o *OriginStorage) SetAccount(addr common.Address) { | ||
if !common.CalAccessList { | ||
return | ||
} | ||
o.mu.Lock() | ||
defer o.mu.Unlock() | ||
if _, ok := o.Data[addr]; !ok { | ||
o.Data[addr] = make(Storage) | ||
} | ||
} | ||
|
||
func (o *OriginStorage) SetOrigin(addr common.Address, hash common.Hash) { | ||
if !common.CalAccessList { | ||
return | ||
} | ||
o.mu.Lock() | ||
defer o.mu.Unlock() | ||
if _, ok := o.Data[addr]; !ok { | ||
o.Data[addr] = make(Storage) | ||
} | ||
o.Data[addr][hash] = common.Hash{} | ||
} | ||
|
||
func (o *OriginStorage) GetData(addr common.Address, hash common.Hash) common.Hash { | ||
scf0220 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if _, ok := o.Data[addr]; !ok { | ||
return common.Hash{} | ||
} | ||
return o.Data[addr][hash] | ||
} | ||
|
||
var emptyCodeHash = crypto.Keccak256(nil) | ||
|
||
type Code []byte | ||
|
@@ -182,6 +259,16 @@ func (s *stateObject) GetState(db Database, key common.Hash) common.Hash { | |
return s.GetCommittedState(db, key) | ||
} | ||
|
||
func (s *stateObject) getCommittedStateFromDB(db Database, key common.Hash) { | ||
t := s.getTrie(db) | ||
enc, _ := t.TryGet(key.Bytes()) | ||
var value common.Hash | ||
if len(enc) > 0 { | ||
_, content, _, _ := rlp.Split(enc) | ||
value.SetBytes(content) | ||
} | ||
} | ||
|
||
// GetCommittedState retrieves a value from the committed account storage trie. | ||
func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Hash { | ||
// If the fake storage is set, only lookup the state here(in the debugging mode) | ||
|
@@ -195,6 +282,13 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has | |
if value, cached := s.originStorage[key]; cached { | ||
return value | ||
} | ||
|
||
if !common.CalAccessList { | ||
load := s.db.OrigForPreLoad.GetData(s.address, key) | ||
s.originStorage[key] = load | ||
return load | ||
} | ||
|
||
// If no live objects are available, attempt to use snapshots | ||
var ( | ||
enc []byte | ||
|
@@ -222,6 +316,7 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has | |
} | ||
if enc, err = s.getTrie(db).TryGet(key.Bytes()); err != nil { | ||
s.setError(err) | ||
s.db.OrigForCalAccessList.SetOrigin(s.address, key) | ||
return common.Hash{} | ||
} | ||
} | ||
|
@@ -234,6 +329,7 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has | |
value.SetBytes(content) | ||
} | ||
s.originStorage[key] = value | ||
s.db.OrigForCalAccessList.SetOrigin(s.address, key) | ||
return value | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.