-
Notifications
You must be signed in to change notification settings - Fork 29
Hotfix - estimate gas #13
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,55 +11,23 @@ import ( | |
| "github.com/ethereum/go-ethereum/log" | ||
| ) | ||
|
|
||
| type stateManagerFunctionAndGasCost struct { | ||
| smFunction stateManagerFunction | ||
| smGasCost uint64 | ||
| } | ||
| type stateManagerFunction func(*EVM, *Contract, []byte) ([]byte, error) | ||
|
|
||
| var funcs = map[string]stateManagerFunctionAndGasCost{ | ||
| "getStorage(address,bytes32)": { | ||
| smFunction: getStorage, | ||
| smGasCost: 20000, | ||
| }, | ||
| "setStorage(address,bytes32,bytes32)": { | ||
| smFunction: setStorage, | ||
| smGasCost: 20000, | ||
| }, | ||
| "getOvmContractNonce(address)": { | ||
| smFunction: getOvmContractNonce, | ||
| smGasCost: 20000, | ||
| }, | ||
| "incrementOvmContractNonce(address)": { | ||
| smFunction: incrementOvmContractNonce, | ||
| smGasCost: 20000, | ||
| }, | ||
| "getCodeContractBytecode(address)": { | ||
| smFunction: getCodeContractBytecode, | ||
| smGasCost: 20000, | ||
| }, | ||
| "getCodeContractHash(address)": { | ||
| smFunction: getCodeContractHash, | ||
| smGasCost: 20000, | ||
| }, | ||
| "getCodeContractAddressFromOvmAddress(address)": { | ||
| smFunction: getCodeContractAddress, | ||
| smGasCost: 20000, | ||
| }, | ||
| "associateCodeContract(address,address)": { | ||
| smFunction: associateCodeContract, | ||
| smGasCost: 20000, | ||
| }, | ||
| "registerCreatedContract(address)": { | ||
| smFunction: registerCreatedContract, | ||
| smGasCost: 20000, | ||
| }, | ||
| var funcs = map[string]stateManagerFunction{ | ||
| "getStorage(address,bytes32)": getStorage, | ||
| "setStorage(address,bytes32,bytes32)": setStorage, | ||
| "getOvmContractNonce(address)": getOvmContractNonce, | ||
| "incrementOvmContractNonce(address)": incrementOvmContractNonce, | ||
| "getCodeContractBytecode(address)": getCodeContractBytecode, | ||
| "getCodeContractHash(address)": getCodeContractHash, | ||
| "getCodeContractAddressFromOvmAddress(address)": getCodeContractAddress, | ||
| "associateCodeContract(address,address)": associateCodeContract, | ||
| "registerCreatedContract(address)": registerCreatedContract, | ||
| } | ||
|
|
||
| var methodIds map[[4]byte]stateManagerFunctionAndGasCost | ||
| var methodIds map[[4]byte]stateManagerFunction | ||
|
|
||
| func init() { | ||
| methodIds = make(map[[4]byte]stateManagerFunctionAndGasCost, len(funcs)) | ||
| methodIds = make(map[[4]byte]stateManagerFunction, len(funcs)) | ||
| for methodSignature, f := range funcs { | ||
| methodIds[methodSignatureToMethodID(methodSignature)] = f | ||
| } | ||
|
|
@@ -71,24 +39,16 @@ func methodSignatureToMethodID(methodSignature string) [4]byte { | |
| return methodID | ||
| } | ||
|
|
||
| func stateManagerRequiredGas(input []byte) (gas uint64) { | ||
| var methodID [4]byte | ||
| copy(methodID[:], input[:4]) | ||
| gas = methodIds[methodID].smGasCost | ||
| return gas | ||
| } | ||
|
|
||
| func callStateManager(input []byte, evm *EVM, contract *Contract) (ret []byte, err error) { | ||
| var methodID [4]byte | ||
| if len(input) == 0 { | ||
| return nil, nil | ||
| } | ||
| copy(methodID[:], input[:4]) | ||
| ret, err = methodIds[methodID].smFunction(evm, contract, input) | ||
| ret, err = methodIds[methodID](evm, contract, input) | ||
|
Collaborator
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. Since if method, ok := methodIds[methodID]; ok {
ret, err = method(evm, contract, input)
return ret, err
}
return nil, errors.New("Method not found")I don't love the way that the error case of "method not found" isn't returned immediately. To fix this we would check
Collaborator
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. You could define |
||
| return ret, err | ||
| } | ||
|
|
||
| /* | ||
| * StateManager functions | ||
| */ | ||
|
|
||
| func setStorage(evm *EVM, contract *Contract, input []byte) (ret []byte, err error) { | ||
| address := common.BytesToAddress(input[4:36]) | ||
| key := common.BytesToHash(input[36:68]) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -366,7 +366,13 @@ func (h *handler) handleSubscribe(cp *callProc, msg *jsonrpcMessage) *jsonrpcMes | |
|
|
||
| // runMethod runs the Go callback for an RPC method. | ||
| func (h *handler) runMethod(ctx context.Context, msg *jsonrpcMessage, callb *callback, args []reflect.Value) *jsonrpcMessage { | ||
| result, err := callb.call(ctx, msg.Method, args) | ||
| var result interface{} | ||
| var err error | ||
| if msg.Method == "eth_estimateGas" { | ||
| result = 0xffffffff //Gas Limit | ||
|
Collaborator
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. I think this may make sense to have in a global variable someplace |
||
| } else { | ||
| result, err = callb.call(ctx, msg.Method, args) | ||
| } | ||
| if err != nil { | ||
| return msg.errorResponse(err) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing the
Errorkey here before theerr. It looks like in this case it'll appendniland the formatting will look weird.See:
go-ethereum/log/logger.go
Line 209 in fa42b78