Skip to content

Commit

Permalink
Move wasm-only code into wasm build flags
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower committed Sep 12, 2024
1 parent 7e7d4ff commit ad31b75
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 15 deletions.
15 changes: 0 additions & 15 deletions core/rawdb/accessors_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ package rawdb

import (
"encoding/binary"
"errors"

"github.com/cockroachdb/pebble"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethdb/memorydb"
"github.com/ethereum/go-ethereum/log"
"github.com/syndtr/goleveldb/leveldb"
)

// ReadSnapshotDisabled retrieves if the snapshot maintenance is disabled.
Expand Down Expand Up @@ -76,17 +72,6 @@ func DeleteSnapshotRoot(db ethdb.KeyValueWriter) {
}
}

func isDbErrNotFound(err error) bool {
return errors.Is(err, leveldb.ErrNotFound) || errors.Is(err, pebble.ErrNotFound) || errors.Is(err, memorydb.ErrMemorydbNotFound)
}

func ignoreNotFound(blob []byte, err error) ([]byte, error) {
if isDbErrNotFound(err) {
return nil, nil
}
return blob, err
}

// ReadAccountSnapshot retrieves the snapshot entry of an account trie leaf.
func ReadAccountSnapshot(db ethdb.KeyValueReader, hash common.Hash) ([]byte, error) {
return ignoreNotFound(db.Get(accountSnapshotKey(hash)))
Expand Down
26 changes: 26 additions & 0 deletions core/rawdb/arbitrum_not_found.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2024 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package rawdb

// Arbitrum specific code to handle database errors

func ignoreNotFound(blob []byte, err error) ([]byte, error) {
if isDbErrNotFound(err) {
return nil, nil
}
return blob, err
}
32 changes: 32 additions & 0 deletions core/rawdb/arbitrum_not_found_native.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2024 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

//go:build !wasm
// +build !wasm

package rawdb

import (
"errors"

"github.com/cockroachdb/pebble"
"github.com/ethereum/go-ethereum/ethdb/memorydb"
"github.com/syndtr/goleveldb/leveldb"
)

func isDbErrNotFound(err error) bool {
return errors.Is(err, leveldb.ErrNotFound) || errors.Is(err, pebble.ErrNotFound) || errors.Is(err, memorydb.ErrMemorydbNotFound)
}
30 changes: 30 additions & 0 deletions core/rawdb/arbitrum_not_found_wasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2024 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

//go:build wasm
// +build wasm

package rawdb

import (
"errors"

"github.com/ethereum/go-ethereum/ethdb/memorydb"
)

func isDbErrNotFound(err error) bool {
return errors.Is(err, memorydb.ErrMemorydbNotFound)
}

0 comments on commit ad31b75

Please sign in to comment.