Skip to content

Commit

Permalink
Merge branch 'master' into cross-compile
Browse files Browse the repository at this point in the history
  • Loading branch information
magicxyyz committed Aug 30, 2024
2 parents d87e573 + cf99ffa commit 10a1004
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 48 deletions.
37 changes: 32 additions & 5 deletions .github/workflows/submodule-pin-check.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
name: Submodule Pin Check
name: Merge Checks

on:
pull_request:
pull_request_target:
branches: [ master ]
types: [synchronize, opened, reopened]

permissions:
statuses: write

jobs:
submodule-pin-check:
name: Submodule Pin Check
name: Check Submodule Pin
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
submodules: true

- name: Check all submodules are ancestors of origin/HEAD or configured branch
run: ${{ github.workspace }}/.github/workflows/submodule-pin-check.sh
run: |
status_state="pending"
if ${{ github.workspace }}/.github/workflows/submodule-pin-check.sh; then
status_state="success"
else
resp="$(curl -sSL --fail-with-body \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/commits/${{ github.event.pull_request.head.sha }}/statuses")"
if ! jq -e '.[] | select(.context == "Submodule Pin Check")' > /dev/null <<< "$resp"; then
# Submodule pin check is failling and no status exists
# Keep it without a status to keep the green checkmark appearing
# Otherwise, the commit and PR's CI will appear to be indefinitely pending
# Merging will still be blocked until the required status appears
exit 0
fi
fi
curl -sSL --fail-with-body \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{ github.event.pull_request.head.sha }}" \
-d '{"context":"Submodule Pin Check","state":"'"$status_state"'"}'
8 changes: 8 additions & 0 deletions arbos/programs/cgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,13 @@ func TestCompileArch(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = resetNativeTarget()
if err != nil {
t.Fatal(err)
}
err = testCompileLoad()
if err != nil {
t.Fatal(err)
}
}
}
2 changes: 1 addition & 1 deletion arbos/programs/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func ResizeWasmLruCache(size uint32) {
}

const DefaultTargetDescriptionArm = "arm64-linux-unknown+neon"
const DefaultTargetDescriptionX86 = "x86_64-linux-unknown+sse4.2"
const DefaultTargetDescriptionX86 = "x86_64-linux-unknown+sse4.2+lzcnt+bmi"

func SetTarget(name ethdb.WasmTarget, description string, native bool) error {
output := &rustBytes{}
Expand Down
22 changes: 22 additions & 0 deletions arbos/programs/testcompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,28 @@ func testCompileArch(store bool) error {
return nil
}

func resetNativeTarget() error {
output := &rustBytes{}

_, err := fmt.Print("resetting native target\n")
if err != nil {
return err
}

localCompileName := []byte("local")

status := C.stylus_target_set(goSlice(localCompileName),
goSlice([]byte{}),
output,
cbool(true))

if status != 0 {
return fmt.Errorf("failed setting compilation target arm: %v", string(output.intoBytes()))
}

return nil
}

func testCompileLoad() error {
filePath := "../../target/testdata/host.bin"
localTarget := rawdb.LocalTarget()
Expand Down
89 changes: 47 additions & 42 deletions cmd/nitro/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,51 @@ func validateOrUpgradeWasmStoreSchemaVersion(db ethdb.Database) error {
return nil
}

func rebuildLocalWasm(ctx context.Context, config *gethexec.Config, l2BlockChain *core.BlockChain, chainDb, wasmDb ethdb.Database, rebuildMode string) (ethdb.Database, *core.BlockChain, error) {
var err error
latestBlock := l2BlockChain.CurrentBlock()
if latestBlock == nil || latestBlock.Number.Uint64() <= l2BlockChain.Config().ArbitrumChainParams.GenesisBlockNum ||
types.DeserializeHeaderExtraInformation(latestBlock).ArbOSFormatVersion < params.ArbosVersion_Stylus {
// If there is only genesis block or no blocks in the blockchain, set Rebuilding of wasm store to Done
// If Stylus upgrade hasn't yet happened, skipping rebuilding of wasm store
log.Info("Setting rebuilding of wasm store to done")
if err = gethexec.WriteToKeyValueStore(wasmDb, gethexec.RebuildingPositionKey, gethexec.RebuildingDone); err != nil {
return nil, nil, fmt.Errorf("unable to set rebuilding status of wasm store to done: %w", err)
}
} else if rebuildMode != "false" {
var position common.Hash
if rebuildMode == "force" {
log.Info("Commencing force rebuilding of wasm store by setting codehash position in rebuilding to beginning")
if err := gethexec.WriteToKeyValueStore(wasmDb, gethexec.RebuildingPositionKey, common.Hash{}); err != nil {
return nil, nil, fmt.Errorf("unable to initialize codehash position in rebuilding of wasm store to beginning: %w", err)
}
} else {
position, err = gethexec.ReadFromKeyValueStore[common.Hash](wasmDb, gethexec.RebuildingPositionKey)
if err != nil {
log.Info("Unable to get codehash position in rebuilding of wasm store, its possible it isnt initialized yet, so initializing it and starting rebuilding", "err", err)
if err := gethexec.WriteToKeyValueStore(wasmDb, gethexec.RebuildingPositionKey, common.Hash{}); err != nil {
return nil, nil, fmt.Errorf("unable to initialize codehash position in rebuilding of wasm store to beginning: %w", err)
}
}
}
if position != gethexec.RebuildingDone {
startBlockHash, err := gethexec.ReadFromKeyValueStore[common.Hash](wasmDb, gethexec.RebuildingStartBlockHashKey)
if err != nil {
log.Info("Unable to get start block hash in rebuilding of wasm store, its possible it isnt initialized yet, so initializing it to latest block hash", "err", err)
if err := gethexec.WriteToKeyValueStore(wasmDb, gethexec.RebuildingStartBlockHashKey, latestBlock.Hash()); err != nil {
return nil, nil, fmt.Errorf("unable to initialize start block hash in rebuilding of wasm store to latest block hash: %w", err)
}
startBlockHash = latestBlock.Hash()
}
log.Info("Starting or continuing rebuilding of wasm store", "codeHash", position, "startBlockHash", startBlockHash)
if err := gethexec.RebuildWasmStore(ctx, wasmDb, chainDb, config.RPC.MaxRecreateStateDepth, &config.StylusTarget, l2BlockChain, position, startBlockHash); err != nil {
return nil, nil, fmt.Errorf("error rebuilding of wasm store: %w", err)
}
}
}
return chainDb, l2BlockChain, nil
}

func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeConfig, chainId *big.Int, cacheConfig *core.CacheConfig, targetConfig *gethexec.StylusTargetConfig, persistentConfig *conf.PersistentConfig, l1Client arbutil.L1Interface, rollupAddrs chaininfo.RollupAddresses) (ethdb.Database, *core.BlockChain, error) {
if !config.Init.Force {
if readOnlyDb, err := stack.OpenDatabaseWithFreezerWithExtraOptions("l2chaindata", 0, 0, config.Persistent.Ancient, "l2chaindata/", true, persistentConfig.Pebble.ExtraOptions("l2chaindata")); err == nil {
Expand Down Expand Up @@ -562,47 +607,7 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo
return chainDb, l2BlockChain, fmt.Errorf("failed to recreate missing states: %w", err)
}
}
latestBlock := l2BlockChain.CurrentBlock()
if latestBlock == nil || latestBlock.Number.Uint64() <= chainConfig.ArbitrumChainParams.GenesisBlockNum ||
types.DeserializeHeaderExtraInformation(latestBlock).ArbOSFormatVersion < params.ArbosVersion_Stylus {
// If there is only genesis block or no blocks in the blockchain, set Rebuilding of wasm store to Done
// If Stylus upgrade hasn't yet happened, skipping rebuilding of wasm store
log.Info("Setting rebuilding of wasm store to done")
if err = gethexec.WriteToKeyValueStore(wasmDb, gethexec.RebuildingPositionKey, gethexec.RebuildingDone); err != nil {
return nil, nil, fmt.Errorf("unable to set rebuilding status of wasm store to done: %w", err)
}
} else if config.Init.RebuildLocalWasm != "false" {
var position common.Hash
if config.Init.RebuildLocalWasm == "force" {
log.Info("Commencing force rebuilding of wasm store by setting codehash position in rebuilding to beginning")
if err := gethexec.WriteToKeyValueStore(wasmDb, gethexec.RebuildingPositionKey, common.Hash{}); err != nil {
return nil, nil, fmt.Errorf("unable to initialize codehash position in rebuilding of wasm store to beginning: %w", err)
}
} else {
position, err = gethexec.ReadFromKeyValueStore[common.Hash](wasmDb, gethexec.RebuildingPositionKey)
if err != nil {
log.Info("Unable to get codehash position in rebuilding of wasm store, its possible it isnt initialized yet, so initializing it and starting rebuilding", "err", err)
if err := gethexec.WriteToKeyValueStore(wasmDb, gethexec.RebuildingPositionKey, common.Hash{}); err != nil {
return nil, nil, fmt.Errorf("unable to initialize codehash position in rebuilding of wasm store to beginning: %w", err)
}
}
}
if position != gethexec.RebuildingDone {
startBlockHash, err := gethexec.ReadFromKeyValueStore[common.Hash](wasmDb, gethexec.RebuildingStartBlockHashKey)
if err != nil {
log.Info("Unable to get start block hash in rebuilding of wasm store, its possible it isnt initialized yet, so initializing it to latest block hash", "err", err)
if err := gethexec.WriteToKeyValueStore(wasmDb, gethexec.RebuildingStartBlockHashKey, latestBlock.Hash()); err != nil {
return nil, nil, fmt.Errorf("unable to initialize start block hash in rebuilding of wasm store to latest block hash: %w", err)
}
startBlockHash = latestBlock.Hash()
}
log.Info("Starting or continuing rebuilding of wasm store", "codeHash", position, "startBlockHash", startBlockHash)
if err := gethexec.RebuildWasmStore(ctx, wasmDb, chainDb, config.Execution.RPC.MaxRecreateStateDepth, &config.Execution.StylusTarget, l2BlockChain, position, startBlockHash); err != nil {
return nil, nil, fmt.Errorf("error rebuilding of wasm store: %w", err)
}
}
}
return chainDb, l2BlockChain, nil
return rebuildLocalWasm(ctx, &config.Execution, l2BlockChain, chainDb, wasmDb, config.Init.RebuildLocalWasm)
}
readOnlyDb.Close()
} else if !dbutil.IsNotExistError(err) {
Expand Down Expand Up @@ -824,7 +829,7 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo
return chainDb, l2BlockChain, err
}

return chainDb, l2BlockChain, nil
return rebuildLocalWasm(ctx, &config.Execution, l2BlockChain, chainDb, wasmDb, config.Init.RebuildLocalWasm)
}

func testTxIndexUpdated(chainDb ethdb.Database, lastBlock uint64) bool {
Expand Down
3 changes: 3 additions & 0 deletions precompiles/ArbOwner.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ func (con ArbOwner) SetL2BaseFee(c ctx, evm mech, priceInWei huge) error {

// SetMinimumL2BaseFee sets the minimum base fee needed for a transaction to succeed
func (con ArbOwner) SetMinimumL2BaseFee(c ctx, evm mech, priceInWei huge) error {
if c.txProcessor.MsgIsNonMutating() && priceInWei.Sign() == 0 {
return errors.New("minimum base fee must be nonzero")
}
return c.State.L2PricingState().SetMinBaseFeeWei(priceInWei)
}

Expand Down

0 comments on commit 10a1004

Please sign in to comment.