Skip to content

Commit

Permalink
Merge branch 'master' into feat/paolo/justified
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenvechain committed Aug 26, 2024
2 parents daf67cc + f1aa5ae commit bde41c3
Show file tree
Hide file tree
Showing 18 changed files with 354 additions and 58 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:
uses: actions/checkout@v4
with:
repository: vechain/thor-e2e-tests
# https://github.com/vechain/thor-e2e-tests/tree/00bd3f1b949b05da94e82686e0089a11a136c34c
ref: 87aeb1747995e8b235a796303b0fc08ab16262c6
# https://github.com/vechain/thor-e2e-tests/tree/d86b30b6409b27e841eace0f7c5b6e75c0a4e25e
ref: d86b30b6409b27e841eace0f7c5b6e75c0a4e25e

- name: Download artifact
uses: actions/download-artifact@v4
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@

## Getting Started

VechainThor is the layer 1 blockchain, highly compatible with EVM<sup>*</sup>, which powers the vechain ecosystem.
VechainThor is a public blockchain that is designed for the mass adoption of blockchain technology by enterprise users
VeChainThor is the layer 1 blockchain, highly compatible with EVM<sup>*</sup>, which powers the VeChain ecosystem.
VeChainThor is a public blockchain that is designed for the mass adoption of blockchain technology by enterprise users
of all sizes and is intended to serve as a foundation for a sustainable and scalable enterprise blockchain ecosystem.

> VechainThor is currently up-to-date with the EVM's `paris` hard fork,
> VeChainThor is currently up-to-date with the EVM's `paris` hard fork,
> set [evmVersion](https://docs.soliditylang.org/en/latest/using-the-compiler.html#setting-the-evm-version-to-target)
> to `paris` if you are using solidity compiler version `0.8.20` or above.
___
Expand All @@ -47,17 +47,17 @@ ___
- [Build](./docs/build.md) - How to build the `thor` binary.
- [Usage](./docs/usage.md) - How to run thor with different configurations.
- [Hosting a Node](./docs/hosting-a-node.md) - Considerations and requirements for hosting a node.
- [Core Concepts](https://docs.vechain.org/core-concepts) - Core concepts of the VechainThor blockchain.
- [API Reference](https://mainnet.vechain.org) - The API reference for the VechainThor blockchain.
- [Core Concepts](https://docs.vechain.org/core-concepts) - Core concepts of the VeChainThor blockchain.
- [API Reference](https://mainnet.vechain.org) - The API reference for the VeChainThor blockchain.

---

## Community

The VechainThor community can be found on [Discourse](https://vechain.discourse.group/) where you can ask questions,
The VeChainThor community can be found on [Discourse](https://vechain.discourse.group/) where you can ask questions,
voice ideas, and share your projects with other people.

The Vechain Improvement Proposals (VIPs) repository can be found [here](https://github.com/vechain/VIPs).
The VeChain Improvement Proposals (VIPs) repository can be found [here](https://github.com/vechain/VIPs).

To chat with other community members you can join:

Expand All @@ -67,16 +67,16 @@ To chat with other community members you can join:
<a href="https://www.reddit.com/r/Vechain"><img src="https://img.shields.io/badge/Reddit-FF4500?style=for-the-badge&logo=reddit&logoColor=white"/></a>
</p>

Do note that our [Code of Conduct](./docs/CODE_OF_CONDUCT.md) applies to all vechain community channels. Users are
Do note that our [Code of Conduct](./docs/CODE_OF_CONDUCT.md) applies to all VeChain community channels. Users are
**highly encouraged** to read and adhere to them to avoid repercussions.

---

## Contributing

Contributions to VechainThor are welcome and highly appreciated. However, before you jump right into it, we would like
Contributions to VeChainThor are welcome and highly appreciated. However, before you jump right into it, we would like
you to review our [Contribution Guidelines](./docs/CONTRIBUTING.md) to make sure you have a smooth experience
contributing to VechainThor.
contributing to VeChainThor.

---

Expand All @@ -102,6 +102,6 @@ A special shout out to following projects:

## License

Vechain Thor is licensed under the [GNU Lesser General Public License v3.0](https://www.gnu.org/licenses/lgpl-3.0.html),
VeChainThor is licensed under the [GNU Lesser General Public License v3.0](https://www.gnu.org/licenses/lgpl-3.0.html),
also included in *LICENSE* file in repository.

103 changes: 103 additions & 0 deletions admin/admin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright (c) 2024 The VeChainThor developers

// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

package admin

import (
"encoding/json"
"log/slog"
"net/http"

"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/vechain/thor/v2/log"
)

type logLevelRequest struct {
Level string `json:"level"`
}

type logLevelResponse struct {
CurrentLevel string `json:"currentLevel"`
}

type errorResponse struct {
ErrorCode int `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}

func writeError(w http.ResponseWriter, errCode int, errMsg string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(errCode)
json.NewEncoder(w).Encode(errorResponse{
ErrorCode: errCode,
ErrorMessage: errMsg,
})
}

func getLogLevelHandler(logLevel *slog.LevelVar) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
response := logLevelResponse{
CurrentLevel: logLevel.Level().String(),
}
if err := json.NewEncoder(w).Encode(response); err != nil {
writeError(w, http.StatusInternalServerError, "Failed to encode response")
}
}
}

func postLogLevelHandler(logLevel *slog.LevelVar) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req logLevelRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
writeError(w, http.StatusBadRequest, "Invalid request body")
return
}

switch req.Level {
case "debug":
logLevel.Set(log.LevelDebug)
case "info":
logLevel.Set(log.LevelInfo)
case "warn":
logLevel.Set(log.LevelWarn)
case "error":
logLevel.Set(log.LevelError)
case "trace":
logLevel.Set(log.LevelTrace)
case "crit":
logLevel.Set(log.LevelCrit)
default:
writeError(w, http.StatusBadRequest, "Invalid verbosity level")
return
}

w.Header().Set("Content-Type", "application/json")
response := logLevelResponse{
CurrentLevel: logLevel.Level().String(),
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(response)
}
}

func logLevelHandler(logLevel *slog.LevelVar) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
getLogLevelHandler(logLevel).ServeHTTP(w, r)
case http.MethodPost:
postLogLevelHandler(logLevel).ServeHTTP(w, r)
default:
writeError(w, http.StatusMethodNotAllowed, "method not allowed")
}
}
}

func HTTPHandler(logLevel *slog.LevelVar) http.Handler {
router := mux.NewRouter()
router.HandleFunc("/admin/loglevel", logLevelHandler(logLevel))
return handlers.CompressHandler(router)
}
3 changes: 2 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func New(
enableReqLogger bool,
enableMetrics bool,
logsLimit uint64,
allowedTracers map[string]interface{},
) (http.HandlerFunc, func()) {
origins := strings.Split(strings.TrimSpace(allowedOrigins), ",")
for i, o := range origins {
Expand Down Expand Up @@ -82,7 +83,7 @@ func New(
Mount(router, "/blocks")
transactions.New(repo, txPool).
Mount(router, "/transactions")
debug.New(repo, stater, forkConfig, callGasLimit, allowCustomTracer, bft).
debug.New(repo, stater, forkConfig, callGasLimit, allowCustomTracer, bft, allowedTracers).
Mount(router, "/debug")
node.New(nw).
Mount(router, "/node")
Expand Down
18 changes: 14 additions & 4 deletions api/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package debug
import (
"context"
"encoding/json"
"fmt"
"math"
"math/big"
"net/http"
Expand All @@ -29,7 +30,6 @@ import (
"github.com/vechain/thor/v2/state"
"github.com/vechain/thor/v2/thor"
"github.com/vechain/thor/v2/tracers"
"github.com/vechain/thor/v2/tracers/logger"
"github.com/vechain/thor/v2/trie"
"github.com/vechain/thor/v2/tx"
"github.com/vechain/thor/v2/vm"
Expand All @@ -46,16 +46,18 @@ type Debug struct {
forkConfig thor.ForkConfig
callGasLimit uint64
allowCustomTracer bool
allowedTracers map[string]interface{}
bft bft.Committer
}

func New(repo *chain.Repository, stater *state.Stater, forkConfig thor.ForkConfig, callGaslimit uint64, allowCustomTracer bool, bft bft.Committer) *Debug {
func New(repo *chain.Repository, stater *state.Stater, forkConfig thor.ForkConfig, callGaslimit uint64, allowCustomTracer bool, bft bft.Committer, allowedTracers map[string]interface{}) *Debug {
return &Debug{
repo,
stater,
forkConfig,
callGaslimit,
allowCustomTracer,
allowedTracers,
bft,
}
}
Expand Down Expand Up @@ -211,9 +213,17 @@ func (d *Debug) handleTraceCall(w http.ResponseWriter, req *http.Request) error
}

func (d *Debug) createTracer(name string, config json.RawMessage) (tracers.Tracer, error) {
if name == "" {
return logger.NewStructLogger(config)
if strings.TrimSpace(name) == "" {
return nil, fmt.Errorf("tracer name must be defined")
}
_, noTracers := d.allowedTracers["none"]
_, allTracers := d.allowedTracers["all"]

// fail if the requested tracer is not allowed OR if the "all" tracers code isn't active
if _, ok := d.allowedTracers[name]; noTracers || (!ok && !allTracers) {
return nil, fmt.Errorf("creating tracer is not allowed: %s", name)
}

return tracers.DefaultDirectory.New(name, config, d.allowCustomTracer)
}

Expand Down
Loading

0 comments on commit bde41c3

Please sign in to comment.