This repository has been archived by the owner on May 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1293 from silasdavis/metadata-state
Split out metadata cache and interfaces
- Loading branch information
Showing
15 changed files
with
181 additions
and
165 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,24 +1,3 @@ | ||
### Changed | ||
- [Config] Reverted rename of ValidatorAddress to Address in config (each Burrow node has a specific validator key it uses for signing whether or not it is running as a validator right now) | ||
|
||
### Fixed | ||
- [EVM] Return integer overflow error code (not stack overflow) for integer overflow errors | ||
- [Docs] Fix broken examples | ||
- [Deploy] Set input on QueryContract jobs correctly | ||
- [EVM] Fix byte-printing for DebugOpcodes run mode | ||
- [Crypto] Use Tendermint-compatible secp256k1 addressing | ||
- [Natives] Make natives first class contracts and establish Dispatcher and Callable as a common calling convention for natives, EVM, and WASM (pending for WASM). | ||
- [Natives] Fix Ethereum precompile addresses (addresses were padded on right instead of the left) | ||
|
||
|
||
### Added | ||
- [Web3] Implemented Ethereum web3 JSON RPC including sendRawTransaction! | ||
- [Docs] Much docs (see also: https://www.hyperledger.org/blog/2019/10/08/burrow-the-boring-blockchain) | ||
- [Docs] Generate github pages docs index with docsify: https://hyperledger.github.io/burrow/ | ||
- [JS] Publish burrow.js to @hyperledger/burrow | ||
- [State] Store EVM ABI and contract metadata on-chain see [GetMetadata](https://github.com/hyperledger/burrow/blob/e80aad5d8fac1f67dbfec61ea75670f9a38c61a1/protobuf/rpcquery.proto#L25) | ||
- [Tendermint] Upgrade to v0.32.3 | ||
- [Execution] Added IdentifyTx for introducing nodes (binding their NodeID to ValidatorAddress) | ||
- [Natives] Implement Ethereum precompile number 5 - modular exponentiation | ||
|
||
- [State] Split metadata and account state to be kinder to downstream EVM integrators | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package acmstate | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
type metadataInfo struct { | ||
metadata string | ||
updated bool | ||
} | ||
|
||
type MetadataCache struct { | ||
backend MetadataReader | ||
m sync.Map | ||
} | ||
|
||
func NewMetadataCache(backend MetadataReader) *MetadataCache { | ||
return &MetadataCache{ | ||
backend: backend, | ||
} | ||
} | ||
|
||
func (cache *MetadataCache) SetMetadata(metahash MetadataHash, metadata string) error { | ||
cache.m.Store(metahash, &metadataInfo{updated: true, metadata: metadata}) | ||
return nil | ||
} | ||
|
||
func (cache *MetadataCache) GetMetadata(metahash MetadataHash) (string, error) { | ||
metaInfo, err := cache.getMetadata(metahash) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return metaInfo.metadata, nil | ||
} | ||
|
||
// Syncs changes to the backend in deterministic order. Sends storage updates before updating | ||
// the account they belong so that storage values can be taken account of in the update. | ||
func (cache *MetadataCache) Sync(st MetadataWriter) error { | ||
var err error | ||
cache.m.Range(func(key, value interface{}) bool { | ||
hash := key.(MetadataHash) | ||
info := value.(*metadataInfo) | ||
if info.updated { | ||
err = st.SetMetadata(hash, info.metadata) | ||
if err != nil { | ||
return false | ||
} | ||
} | ||
return true | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (cache *MetadataCache) Flush(output MetadataWriter, backend MetadataReader) error { | ||
err := cache.Sync(output) | ||
if err != nil { | ||
return err | ||
} | ||
cache.m = sync.Map{} | ||
return nil | ||
} | ||
|
||
// Get the cache accountInfo item creating it if necessary | ||
func (cache *MetadataCache) getMetadata(metahash MetadataHash) (*metadataInfo, error) { | ||
value, ok := cache.m.Load(metahash) | ||
if !ok { | ||
metadata, err := cache.backend.GetMetadata(metahash) | ||
if err != nil { | ||
return nil, err | ||
} | ||
metaInfo := &metadataInfo{ | ||
metadata: metadata, | ||
} | ||
cache.m.Store(metahash, metaInfo) | ||
return metaInfo, nil | ||
} | ||
return value.(*metadataInfo), nil | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.