Skip to content
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

Xmerge/bor v1.5.1 #46

Open
wants to merge 34 commits into
base: working-copy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7684a47
Copying over plugeth2 resources
philip-morlier Aug 22, 2024
10e40af
removed build chain from mod and set circle config to bor
philip-morlier Aug 23, 2024
2a10448
Merge branch 'xdevelop' of https://github.com/openrelayxyz/plugeth-bo…
Akohjesse Aug 23, 2024
441098b
added xplugeth hooks and injection at triedb
Akohjesse Aug 23, 2024
0b050d5
write out hook and injection at core/state
Akohjesse Aug 23, 2024
f276777
add xplugeth & plugeth utils packages
Akohjesse Aug 23, 2024
304b90f
add hooks and injections at core package
Akohjesse Aug 23, 2024
5e4ae14
make injected function private, removed xplugeth impororts
Akohjesse Aug 26, 2024
23c940c
make injected function private, removed xplugeth impororts
Akohjesse Aug 26, 2024
742a9ae
make injected function private, removed xplugeth impororts
Akohjesse Aug 26, 2024
0b13242
update setTrieFlushCloneInterval plugin
Akohjesse Aug 26, 2024
062325d
write modifyAncients hook & add injection at core/rawdb
Akohjesse Aug 26, 2024
061ff1c
Initial commit of xplugeth injection and hooks in internal/cli/server/
philip-morlier Sep 10, 2024
7f9d9e3
Modified mod and sum to enable building
philip-morlier Sep 10, 2024
6a6b595
Merge remote-tracking branch 'origin/feature/xplugethhooks-core-rawdb…
philip-morlier Sep 10, 2024
573b5a4
Adjusted mod and sum to allow for building
philip-morlier Sep 10, 2024
39388c7
Merge remote-tracking branch 'origin/feature/xplugethhooks-core' into…
philip-morlier Sep 10, 2024
ed4304a
updated mod and sum to allow for building
philip-morlier Sep 11, 2024
ada583d
Adjustments to stateupdate injections as well as adding pluginSnapsho…
philip-morlier Sep 11, 2024
6ef08a0
Merge remote-tracking branch 'origin/feature/xplugethhooks-core-state…
philip-morlier Sep 11, 2024
70f3d9a
Adjustments to mod and sum to enable building
philip-morlier Sep 11, 2024
1a31fff
Merge remote-tracking branch 'origin/feature/xplugethhooks-triedb' in…
philip-morlier Sep 11, 2024
2cb5d65
refactored xplugeth_hook files to internal interface version
philip-morlier Oct 11, 2024
2c26e74
Added plugins config environment variable parser
philip-morlier Oct 11, 2024
b592480
upgraded mod and sum to reflect xplugeth v0.1.0
philip-morlier Oct 11, 2024
88d1446
Merge commit '0b28bb5e2' into xmerge/bor-v1.4.1
philip-morlier Oct 11, 2024
211e35b
changed logging level in internal/cli/server/xplugeth_hooks pluginsCo…
philip-morlier Oct 11, 2024
87dd70a
Added disablePlugins function
philip-morlier Oct 11, 2024
f784482
Added logging for initialize xplugeth
philip-morlier Oct 11, 2024
d8fc46b
Added subscription hook and injection
philip-morlier Oct 17, 2024
f563de2
Added utility function to core/state/xplugeth_hooks
philip-morlier Oct 19, 2024
defcef8
Added xplugeth_imports to gitignore
philip-morlier Oct 21, 2024
64fd449
Merge commit 'ff29b1f2e' into xmerge/bor-v1.5.1
philip-morlier Oct 28, 2024
9a37cee
refactored implementation of pluginStateUpdate injection
philip-morlier Oct 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 98 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,104 @@
# Golang CircleCI 2.0 configuration file
# Check https://circleci.com/docs/2.0/language-go/ for more details
orbs:
aws-cli: circleci/[email protected] #See: https://circleci.com/orbs/registry/orb/circleci/aws-cli

version: 2.1

executors:
golang:
docker:
- image: circleci/golang:1.13
working_directory: /go/src/github.com/ethereum/go-ethereum

version: 2.1
jobs:
build:
executor: golang
test:
docker:
- image: cimg/go:1.22.0
steps:
- checkout
- run:
name: Prep env
command: |
mkdir -p /home/circleci/go/src
mkdir artifacts
go mod tidy
- run:
name: test rpc
command: go test ./rpc/
- run:
name: test eth
command: go test ./eth/
- run:
name: test eth/tracers
command: go test ./eth/tracers/
- run:
name: test core
command: go test ./core/
- run:
name: test core/vm
command: go test ./core/vm/
- run:
name: test core/state
command: go test ./core/state/
- run:
name: test core/rawdb
command: go test ./core/rawdb/
build_geth_push:
docker: # run the steps with Docker
- image: cimg/go:1.22.0 # ...with this image as the primary container
# this is where all `steps` will run
steps:
- checkout # check out source code to working directory
- checkout
- setup_remote_docker
- run:
command: make all
name: Prep env
command: |
mkdir -p /home/circleci/go/src
mkdir artifacts
go mod tidy
- run:
command: make test
name: build geth binaries
command: |
sudo apt update
sudo apt install gcc-aarch64-linux-gnu libc6-dev-arm64-cross wget -y
export GOPATH=$HOME/go
export GOARCH=amd64
go build -o ./artifacts/bor-linux-amd64-${CIRCLE_TAG} ./cmd/cli
CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOARCH=arm64 go build -o ./artifacts/bor-linux-arm64-${CIRCLE_TAG} ./cmd/cli
- run:
name: "Publish Release on GitHub"
command: |
go install github.com/tcnksm/[email protected]
NAME=plugeth2-${CIRCLE_TAG}
VERSION=${CIRCLE_TAG}
ghr -draft -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -name $NAME -delete ${VERSION} ./artifacts/
- aws-cli/setup: #See: https://circleci.com/orbs/registry/orb/circleci/aws-cli
aws-access-key-id: ACCESS_KEY
aws-secret-access-key: SECRET_ACCESS_KEY
aws-region: AWS_REGION
- run:
name: push to s3
command: |
aws s3 cp ./artifacts/bor-linux-amd64-${CIRCLE_TAG} s3://ethercattle-binaries/plugeth2/$CIRCLE_TAG/bor-linux-amd64 --acl=public-read
aws s3 cp ./artifacts/bor-linux-arm64-${CIRCLE_TAG} s3://ethercattle-binaries/plugeth2/$CIRCLE_TAG/bor-linux-arm64 --acl=public-read
- run:
name: Message Slack
command: |
./slack-post.sh -w $SLACK_WEBHOOK -m "*plugeth-bor2*:\nTag: $CIRCLE_TAG \n"

workflows:
version: 2
test:
jobs:
- test:
filters:
tags:
ignore: /^v.*/
build_and_test:
jobs:
- test:
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
- build_geth_push:
context: Rivet
requires:
- test
filters:
tags:
only: /^v.*/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ dist
logs/

tests/spec-tests/

# xplugeth_imports
/internal/cli/server/xplugeth_hooks.go
106 changes: 42 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,60 @@
# Bor Overview
Bor is the Official Golang implementation of the Polygon PoS blockchain. It is a fork of [geth](https://github.com/ethereum/go-ethereum) and is EVM compatible (upto London fork).
# PluGeth

[![API Reference](
https://pkg.go.dev/badge/github.com/maticnetwork/bor
)](https://pkg.go.dev/github.com/maticnetwork/bor)
[![Go Report Card](https://goreportcard.com/badge/github.com/maticnetwork/bor)](https://goreportcard.com/report/github.com/maticnetwork/bor)
![MIT License](https://img.shields.io/github/license/maticnetwork/bor)
[![Discord](https://img.shields.io/badge/discord-join%20chat-blue.svg)](https://discord.com/invite/0xpolygonrnd)
[![Twitter Follow](https://img.shields.io/twitter/follow/0xPolygon.svg?style=social)](https://twitter.com/0xPolygon)
PluGeth is a fork of the [Go Ethereum Client](https://github.com/ethereum/go-ethereum)
(Geth) that implements a plugin architecture, allowing developers to extend
Geth's capabilities in a number of different ways using plugins, rather than
having to create additional, new forks of Geth.

### Installing bor using packaging
Documentation can be found [here](https://plugeth.org).

The easiest way to get started with bor is to install the packages using the command below. Refer to the [releases](https://github.com/maticnetwork/bor/releases) section to find the latest stable version of bor.

curl -L https://raw.githubusercontent.com/maticnetwork/install/main/bor.sh | bash -s -- v0.4.0 <network> <node_type>
## Design Goals

The network accepts `mainnet`,`amoy` or `mumbai` and the node type accepts `validator` or `sentry` or `archive`. The installation script does the following things:
- Create a new user named `bor`.
- Install the bor binary at `/usr/bin/bor`.
- Dump the suitable config file (based on the network and node type provided) at `/var/lib/bor` and uses it as the home dir.
- Create a systemd service named `bor` at `/lib/systemd/system/bor.service` which starts bor using the config file as `bor` user.
The upstream Geth client exists primarily to serve as a client for the Ethereum
mainnet, though it also supports a number of popular testnets. Supporting the
Ethereum mainnet is a big enough challenge in its own right that the Geth team
generally avoids changes to support other networks, or to provide features only
a small handful of users would be interested in.

The releases supports both the networks i.e. Polygon Mainnet, Amoy and Mumbai (Testnet) unless explicitly specified. Before the stable release for mainnet, pre-releases will be available marked with `beta` tag for deploying on Mumbai/Amoy (testnet). On sufficient testing, stable release for mainnet will be announced with a forum post.
The result is that many projects have forked Geth. Some implement their own
consensus protocols or alter the behavior of the EVM to support other networks.
Others are designed to extract information from the Ethereum mainnet in ways
the standard Geth client does not support.

### Building from source
PluGeth aims to provide a single Geth fork that developers can choose to extend
rather than forking the Geth project. Out of the box, PluGeth behaves exactly
like upstream Geth, but by installing plugins written in Golang, developers can
extend its functionality in a wide variety of way.

- Install Go (version 1.19 or later) and a C compiler.
- Clone the repository and build the binary using the following commands:
```shell
make bor
```
- Start bor using the ideal config files for validator and sentry provided in the `packaging` folder.
```shell
./build/bin/bor server --config ./packaging/templates/mainnet-v1/sentry/sentry/bor/config.toml
```
- To build full set of utilities, run:
```shell
make all
```
- Run unit and integration tests
```shell
make test && make test-integration
```
### Submitting Pull Requests

#### Using the new cli
We are eager to include contributions from the community into the project. We ask that pull requests which include new features to be covered by our test plugin found in: `/plugins/test-plugin`. The test design and instructions for use are documented there. If further assistance is needed please get in touch with us.

Post `v0.3.0` release, bor uses a new command line interface (cli). The new-cli (located at `internal/cli`) has been built with keeping the flag usage similar to old-cli (located at `cmd/geth`) with a few notable changes. Please refer to [docs](./docs) section for flag usage guide and example.
### Contact Us

### Documentation
If you're trying to do something that isn't supported by the current plugin system, Reach out to us on [Discord](https://discord.gg/Epf7b7Gr) and we'll help you figure out how to make it work.

- The official documentation for the Polygon PoS chain can be found [here](https://wiki.polygon.technology/docs/pos/getting-started/). It contains all the conceptual and architectural details of the chain along with operational guide for users running the nodes.
- New release announcements and discussions can be found on our [forum page](https://forum.polygon.technology/).
- Polygon improvement proposals can be found [here](https://github.com/maticnetwork/Polygon-Improvement-Proposals/)
## System Requirements

### Contribution guidelines
System requirements will vary depending on which network you are connecting to.
On the Ethereum mainnet, you should have at least 8 GB RAM, 2 CPUs, and 350 GB
of SSD disks.

Thank you for considering helping out with the source code! We welcome contributions from anyone on the internet, and are grateful for even the smallest of fixes! If you'd like to contribute to bor, please fork, fix, commit and send a pull request for the maintainers to review and merge into the main code base.
PluGeth relies on Golang's Plugin implementation, which is only supported on
Linux, FreeBSD, and macOS. Windows support is unlikely to be added in the
foreseeable future.

From the outset we defined some guidelines to ensure new contributions only ever enhance the project:
# Licensing Considerations

* Quality: Code in the Polygon project should meet the style guidelines, with sufficient test-cases, descriptive commit messages, evidence that the contribution does not break any compatibility commitments or cause adverse feature interactions, and evidence of high-quality peer-review. Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)).
* Testing: Please ensure that the updated code passes all the tests locally before submitting a pull request. In order to run unit tests, run `make test` and to run integration tests, run `make test-integration`.
* Size: The Polygon project’s culture is one of small pull-requests, regularly submitted. The larger a pull-request, the more likely it is that you will be asked to resubmit as a series of self-contained and individually reviewable smaller PRs.
* Maintainability: If the feature will require ongoing maintenance (e.g. support for a particular brand of database), we may ask you to accept responsibility for maintaining this feature
* Pull requests need to be based on and opened against the `develop` branch.
* PR title should be prefixed with package(s) they modify.
* E.g. "eth, rpc: make trace configs optional"
The Geth codebase is licensed under the LGPL. By linking with Geth, you have an
obligation to enable anyone you provide your plugin binaries to run against
their own modified versions of Geth. Because of how Golang plugins work
running against updated versions of Geth may require recompiling the plugin.

## License
If you plan to license your plugin under the LGPL or a more permissive license,
you should be able to meet these requirements. If you plan to use your plugin
privately without distributing it, you should be fine. If you plan to release
your plugin without making the source available, you may find yourself in
violation of Geth's license unless you can provide a way to relink it against
more recent versions of Geth.

The go-ethereum library (i.e. all code outside of the `cmd` directory) is licensed under the
[GNU Lesser General Public License v3.0](https://www.gnu.org/licenses/lgpl-3.0.en.html),
also included in our repository in the `COPYING.LESSER` file.

The go-ethereum binaries (i.e. all code inside of the `cmd` directory) are licensed under the
[GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.en.html), also
included in our repository in the `COPYING` file.

## Join our Discord server

Join Polygon community – share your ideas or just say hi over on [Polygon Community Discord](https://discord.com/invite/0xPolygonCommunity) or on [Polygon R&D Discord](https://discord.com/invite/0xpolygonrnd).
15 changes: 5 additions & 10 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# Polygon Technology Security Information
# Security Policy

## Link to vulnerability disclosure details (Bug Bounty)
- Websites and Applications: https://hackerone.com/polygon-technology
- Smart Contracts: https://immunefi.com/bounty/polygon

## Languages that our team speaks and understands.
Preferred-Languages: en

## Security-related job openings at Polygon.
https://polygon.technology/careers
Please see [Releases](https://github.com/openrelayxyz/plugeth/releases) for notes on each release. We recommend using the most recently released version.

## Polygon security contact details
[email protected]
To report security issues in the underlying Geth code code please see Geth's security policy [here](https://github.com/ethereum/go-ethereum/security/policy).

To report PluGeth specific issues please email [[email protected]](mailto:[email protected]).
32 changes: 0 additions & 32 deletions circle.yml

This file was deleted.

34 changes: 33 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,10 @@ func (bc *BlockChain) writeKnownBlock(block *types.Block) error {
// writeBlockWithState writes block, metadata and corresponding state data to the
// database.
func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, statedb *state.StateDB) ([]*types.Log, error) {
//begin PluGeth injection
var interval time.Duration
_ = pluginSetTrieFlushIntervalClone(interval) // this is being called here to engage a testing scenario
//end PluGeth injection
// Calculate the total difficulty of the block
ptd := bc.GetTd(block.ParentHash(), block.NumberU64()-1)
if ptd == nil {
Expand Down Expand Up @@ -1869,6 +1873,11 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
chosen := current - state.TriesInMemory
flushInterval := time.Duration(bc.flushInterval.Load())
// If we exceeded time allowance, flush an entire trie to disk

// begin PluGeth code injection
flushInterval = pluginSetTrieFlushIntervalClone(flushInterval)
// end PluGeth code injection

if bc.gcproc > flushInterval {
// If the header is missing (canonical chain behind), we're reorging a low
// diff sidechain. Suspend committing until this operation is completed.
Expand Down Expand Up @@ -1943,7 +1952,17 @@ func (bc *BlockChain) writeBlockAndSetHead(ctx context.Context, block *types.Blo
if status == CanonStatTy {
bc.writeHeadBlock(block)
}
//begin PluGeth code injection
ptd := bc.GetTd(block.ParentHash(), block.NumberU64()-1)
if ptd == nil {
return NonStatTy, consensus.ErrUnknownAncestor
}
externTd := new(big.Int).Add(block.Difficulty(), ptd)
// end PluGeth code injection
if status == CanonStatTy {
// begin plugeth injection
pluginNewHead(block, block.Hash(), logs, externTd)
// end plugeth injection
bc.chainFeed.Send(ChainEvent{Block: block, Hash: block.Hash(), Logs: logs})

if len(logs) > 0 {
Expand All @@ -1969,6 +1988,9 @@ func (bc *BlockChain) writeBlockAndSetHead(ctx context.Context, block *types.Blo
// BOR
}
} else {
//begin PluGeth injection
pluginNewSideBlock(block, block.Hash(), logs)
//end PluGeth injection
bc.chainSideFeed.Send(ChainSideEvent{Block: block})

bc.chain2HeadFeed.Send(Chain2HeadEvent{
Expand Down Expand Up @@ -2904,7 +2926,9 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Block) error {
msg = "Large chain reorg detected"
logFn = log.Warn
}

//begin PluGeth code injection
pluginReorg(commonBlock, oldChain, newChain)
//end PluGeth code injection
logFn(msg, "number", commonBlock.Number(), "hash", commonBlock.Hash(),
"drop", len(oldChain), "dropfrom", oldChain[0].Hash(), "add", len(newChain), "addfrom", newChain[0].Hash())
blockReorgAddMeter.Mark(int64(len(newChain)))
Expand Down Expand Up @@ -3138,6 +3162,14 @@ func (bc *BlockChain) SetCanonical(head *types.Block) (common.Hash, error) {
bc.logsFeed.Send(logs)
}

// begin PluGeth code injection
ptd := bc.GetTd(head.ParentHash(), head.NumberU64()-1)
externTd := ptd
if ptd != nil {
externTd = new(big.Int).Add(head.Difficulty(), ptd)
}
pluginNewHead(head, head.Hash(), logs, externTd)
// end PluGeth code injection
bc.chainHeadFeed.Send(ChainHeadEvent{Block: head})

context := []interface{}{
Expand Down
3 changes: 3 additions & 0 deletions core/rawdb/freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ func (f *Freezer) ModifyAncients(fn func(ethdb.AncientWriteOp) error) (writeSize
if err != nil {
return 0, err
}
//begin PluGeth code injection
pluginCommitUpdate(item)
//end PluGeth code injection
f.frozen.Store(item)
return writeSize, nil
}
Expand Down
Loading
Loading